Skip to content

[DX-3414] test: android ui tests for pkce relogin, reconnect, connect and logout #375

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
Jan 16, 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 @@ -10,6 +10,7 @@ class TestConfig:
EMAIL = "[email protected]"
PASSPORT_ID="email|67480492219c150aceeb1f37"
WALLET_ADDRESS = "0x547044ea95f03651139081241c99ffedbefdc5e8"
ANDROID_PACKAGE = "com.immutable.ImmutableSample"

class UnityTest(unittest.TestCase):

Expand Down
171 changes: 156 additions & 15 deletions sample/Tests/test/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from alttester import *

from test import UnityTest
from test import TestConfig, UnityTest

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

def test_1_pkce_login(self):
# 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")

# Login
loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn")
loginBtn.tap()

driver = self.appium_driver
@classmethod
def login(cls):
driver = cls.appium_driver

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

# Ensure the latest window is active as the previous window might have been closed
handles = driver.window_handles
driver.switch_to.window(handles[-1])

email_field = driver.find_element(by=AppiumBy.XPATH, value="//input[@name=\"address\"]")
email_field.send_keys(EMAIL)
submit_button = driver.find_element(by=AppiumBy.XPATH, value="//form/div/div/div[2]/button")
Expand All @@ -74,6 +67,36 @@ def test_1_pkce_login(self):
otp_field = driver.find_element(by=AppiumBy.XPATH, value="//div[@id=\"passwordless_container\"]/div[1]/input")
otp_field.send_keys(code)

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

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

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

def test_1_pkce_login(self):
# 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")

# Login
loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn")
loginBtn.tap()

self.login()

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

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

def test_5_zkevm_functions(self):
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