Skip to content

Commit 8b9d358

Browse files
committed
test: android ui tests for pkce relogin, reconnect, connect and logout
1 parent 0094e72 commit 8b9d358

File tree

2 files changed

+157
-15
lines changed

2 files changed

+157
-15
lines changed

sample/Tests/test/test.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TestConfig:
1010
1111
PASSPORT_ID="email|67480492219c150aceeb1f37"
1212
WALLET_ADDRESS = "0x547044ea95f03651139081241c99ffedbefdc5e8"
13+
ANDROID_PACKAGE = "com.immutable.ImmutableSample"
1314

1415
class UnityTest(unittest.TestCase):
1516

sample/Tests/test/test_android.py

+156-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
from appium import webdriver
77
from appium.options.android import UiAutomator2Options
88
from appium.webdriver.common.appiumby import AppiumBy
9-
from appium.webdriver.webdriver import WebDriver
109
from selenium.webdriver.support.ui import WebDriverWait
11-
from selenium.webdriver.support import expected_conditions as EC
1210

1311
from alttester import *
1412

15-
from test import UnityTest
13+
from test import TestConfig, UnityTest
1614

1715
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'src'))
1816
from fetch_otp import EMAIL, fetch_code
@@ -41,23 +39,18 @@ def tearDownClass(cls):
4139
cls.altdriver.stop()
4240
cls.appium_driver.quit()
4341

44-
def test_1_pkce_login(self):
45-
# Select use PKCE auth
46-
self.altdriver.find_object(By.NAME, "PKCE").tap()
47-
48-
# Wait for unauthenticated screen
49-
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
50-
51-
# Login
52-
loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn")
53-
loginBtn.tap()
54-
55-
driver = self.appium_driver
42+
@classmethod
43+
def login(cls):
44+
driver = cls.appium_driver
5645

5746
# Wait for the Chrome Custom Tabs context to appear
5847
WebDriverWait(driver, 30).until(lambda d: 'WEBVIEW_chrome' in d.contexts)
5948
driver.switch_to.context("WEBVIEW_chrome")
6049

50+
# Ensure the latest window is active as the previous window might have been closed
51+
handles = driver.window_handles
52+
driver.switch_to.window(handles[-1])
53+
6154
email_field = driver.find_element(by=AppiumBy.XPATH, value="//input[@name=\"address\"]")
6255
email_field.send_keys(EMAIL)
6356
submit_button = driver.find_element(by=AppiumBy.XPATH, value="//form/div/div/div[2]/button")
@@ -74,6 +67,36 @@ def test_1_pkce_login(self):
7467
otp_field = driver.find_element(by=AppiumBy.XPATH, value="//div[@id=\"passwordless_container\"]/div[1]/input")
7568
otp_field.send_keys(code)
7669

70+
@classmethod
71+
def close_and_open_app(cls):
72+
driver = cls.appium_driver
73+
74+
# Close app
75+
time.sleep(5)
76+
print("Closing app...")
77+
driver.terminate_app(TestConfig.ANDROID_PACKAGE)
78+
time.sleep(5)
79+
print("Closed app")
80+
81+
# Reopen app
82+
print("Opening app...")
83+
driver.activate_app(TestConfig.ANDROID_PACKAGE)
84+
time.sleep(10)
85+
print("Opened app")
86+
87+
def test_1_pkce_login(self):
88+
# Select use PKCE auth
89+
self.altdriver.find_object(By.NAME, "PKCE").tap()
90+
91+
# Wait for unauthenticated screen
92+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
93+
94+
# Login
95+
loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn")
96+
loginBtn.tap()
97+
98+
self.login()
99+
77100
# Wait for authenticated screen
78101
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
79102

@@ -88,3 +111,121 @@ def test_4_imx_functions(self):
88111

89112
def test_5_zkevm_functions(self):
90113
self.test_3_zkevm_functions()
114+
115+
def test_6_pkce_relogin(self):
116+
driver = self.appium_driver
117+
118+
self.close_and_open_app()
119+
120+
# Restart AltTester
121+
self.altdriver.stop()
122+
self.altdriver = AltDriver()
123+
time.sleep(5)
124+
125+
# # Select use PKCE auth
126+
self.altdriver.find_object(By.NAME, "PKCE").tap()
127+
# Wait for unauthenticated screen
128+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
129+
130+
# Relogin
131+
print("Re-logging in...")
132+
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
133+
134+
# Wait for authenticated screen
135+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
136+
print("Re-logged in")
137+
138+
# Get access token
139+
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
140+
output = self.altdriver.find_object(By.NAME, "Output")
141+
self.assertTrue(len(output.get_text()) > 50)
142+
143+
# Click Connect to IMX button
144+
self.altdriver.find_object(By.NAME, "ConnectBtn").tap()
145+
self.assertEqual("Connected to IMX", output.get_text())
146+
147+
self.altdriver.stop()
148+
149+
def test_7_pkce_reconnect(self):
150+
self.close_and_open_app()
151+
152+
# Restart AltTester
153+
self.altdriver.stop()
154+
self.altdriver = AltDriver()
155+
time.sleep(5)
156+
157+
# Select use PKCE auth
158+
self.altdriver.find_object(By.NAME, "PKCE").tap()
159+
# Wait for unauthenticated screen
160+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
161+
162+
# Reconnect
163+
print("Reconnecting...")
164+
self.altdriver.wait_for_object(By.NAME, "ReconnectBtn").tap()
165+
166+
# Wait for authenticated screen
167+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
168+
print("Reconnected")
169+
170+
# Get access token
171+
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
172+
output = self.altdriver.find_object(By.NAME, "Output")
173+
self.assertTrue(len(output.get_text()) > 50)
174+
175+
# Get address without having to click Connect to IMX button
176+
self.altdriver.find_object(By.NAME, "GetAddressBtn").tap()
177+
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())
178+
179+
# Logout
180+
print("Logging out...")
181+
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
182+
time.sleep(5)
183+
184+
# Wait for authenticated screen
185+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
186+
time.sleep(5)
187+
print("Logged out")
188+
189+
self.altdriver.stop()
190+
191+
def test_8_pkce_connect_imx(self):
192+
self.close_and_open_app()
193+
194+
# Restart AltTester
195+
self.altdriver.stop()
196+
self.altdriver = AltDriver()
197+
time.sleep(5)
198+
199+
# Select use PKCE auth
200+
self.altdriver.find_object(By.NAME, "PKCE").tap()
201+
# Wait for unauthenticated screen
202+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
203+
204+
# Connect IMX
205+
print("Logging in and connecting to IMX...")
206+
self.altdriver.wait_for_object(By.NAME, "ConnectBtn").tap()
207+
208+
self.login()
209+
210+
# Wait for authenticated screen
211+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
212+
print("Logged in and connected to IMX")
213+
214+
# Get access token
215+
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
216+
output = self.altdriver.find_object(By.NAME, "Output")
217+
self.assertTrue(len(output.get_text()) > 50)
218+
219+
# Get address without having to click Connect to IMX button
220+
self.altdriver.find_object(By.NAME, "GetAddressBtn").tap()
221+
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())
222+
223+
# Logout
224+
print("Logging out...")
225+
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
226+
time.sleep(5)
227+
228+
# Wait for authenticated screen
229+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
230+
time.sleep(5)
231+
print("Logged out")

0 commit comments

Comments
 (0)