Skip to content

[DX-3537] test: ios ui tests for pkce relogin, reconnect, connect and logout #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sample/Tests/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestConfig:
PASSPORT_ID="email|67480492219c150aceeb1f37"
WALLET_ADDRESS = "0x547044ea95f03651139081241c99ffedbefdc5e8"
ANDROID_PACKAGE = "com.immutable.ImmutableSample"
IOS_BUNDLE_ID = "com.immutable.Immutable-Sample"

class UnityTest(unittest.TestCase):

Expand Down
141 changes: 140 additions & 1 deletion sample/Tests/test/test_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def login(cls):

# Wait for the ASWebAuthenticationSession context to appear
WebDriverWait(driver, 30).until(lambda d: len(d.contexts) > 2)
time.sleep(5) # Refresh contexts by waiting before fetching again
print("Available contexts:", driver.contexts)
contexts = driver.contexts
driver.switch_to.context(driver.contexts[-1])
print("Current context:", driver.current_context)

target_context = None

Expand Down Expand Up @@ -89,6 +93,23 @@ def login(cls):
# If target context was not found, raise an error
if not target_context:
raise Exception("Could not find the email field in any webview context.")

@classmethod
def close_and_open_app(cls):
driver = cls.appium_driver

# Close app
time.sleep(5)
print("Closing app...")
driver.terminate_app(TestConfig.IOS_BUNDLE_ID)
time.sleep(5)
print("Closed app")

# Reopen app
print("Opening app...")
driver.activate_app(TestConfig.IOS_BUNDLE_ID)
time.sleep(10)
print("Opened app")

def test_1_pkce_login(self):
# Select use PKCE auth
Expand Down Expand Up @@ -116,4 +137,122 @@ def test_4_imx_functions(self):
self.test_2_imx_functions()

def test_5_zkevm_functions(self):
self.test_3_zkevm_functions()
self.test_3_zkevm_functions()

def test_6_pkce_relogin(self):
driver = self.appium_driver

self.close_and_open_app()

# Restart AltTester
self.altdriver.stop()
self.altdriver = AltDriver()
time.sleep(5)

# # Select use PKCE auth
self.altdriver.find_object(By.NAME, "PKCE").tap()
# Wait for unauthenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")

# Relogin
print("Re-logging in...")
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
print("Re-logged in")

# Get access token
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
output = self.altdriver.find_object(By.NAME, "Output")
self.assertTrue(len(output.get_text()) > 50)

# Click Connect to IMX button
self.altdriver.find_object(By.NAME, "ConnectBtn").tap()
self.assertEqual("Connected to IMX", output.get_text())

self.altdriver.stop()

def test_7_pkce_reconnect(self):
self.close_and_open_app()

# Restart AltTester
self.altdriver.stop()
self.altdriver = AltDriver()
time.sleep(5)

# Select use PKCE auth
self.altdriver.find_object(By.NAME, "PKCE").tap()
# Wait for unauthenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")

# Reconnect
print("Reconnecting...")
self.altdriver.wait_for_object(By.NAME, "ReconnectBtn").tap()

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
print("Reconnected")

# Get access token
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
output = self.altdriver.find_object(By.NAME, "Output")
self.assertTrue(len(output.get_text()) > 50)

# Get address without having to click Connect to IMX button
self.altdriver.find_object(By.NAME, "GetAddressBtn").tap()
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())

# Logout
print("Logging out...")
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
time.sleep(5)

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
time.sleep(5)
print("Logged out")

self.altdriver.stop()

def test_8_pkce_connect_imx(self):
self.close_and_open_app()

# Restart AltTester
self.altdriver.stop()
self.altdriver = AltDriver()
time.sleep(5)

# Select use PKCE auth
self.altdriver.find_object(By.NAME, "PKCE").tap()
# Wait for unauthenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")

# Connect IMX
print("Logging in and connecting to IMX...")
self.altdriver.wait_for_object(By.NAME, "ConnectBtn").tap()

self.login()

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
print("Logged in and connected to IMX")

# Get access token
self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap()
output = self.altdriver.find_object(By.NAME, "Output")
self.assertTrue(len(output.get_text()) > 50)

# Get address without having to click Connect to IMX button
self.altdriver.find_object(By.NAME, "GetAddressBtn").tap()
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())

# Logout
print("Logging out...")
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
time.sleep(5)

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
time.sleep(5)
print("Logged out")
Loading