diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index e1986d39..3f97c934 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -68,7 +68,7 @@ jobs: test_script: ./test_mac.sh - targetPlatform: StandaloneWindows64 runs-on: [self-hosted, windows] - test_script: ./test_windows.ps1 + test_script: pytest -xs test/test_windows.py::WindowsTest - targetPlatform: Android runs-on: [ self-hosted, macOS ] test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml" diff --git a/sample/Tests/src/device_code_login_windows.py b/sample/Tests/src/device_code_login_windows.py deleted file mode 100644 index 74829bd7..00000000 --- a/sample/Tests/src/device_code_login_windows.py +++ /dev/null @@ -1,66 +0,0 @@ -from selenium import webdriver -from selenium.webdriver.chrome.service import Service -from selenium.webdriver.chrome.options import Options -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.keys import Keys -import time -from fetch_otp import EMAIL, fetch_code - -# Add chrome.exe to environment variable -# Download chrome driver and add to environment variable - -def main(): - print("Connect to Chrome") - # Set up Chrome options to connect to the existing Chrome instance - chrome_options = Options() - chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") - # Connect to the existing Chrome instance - driver = webdriver.Chrome(options=chrome_options) - - print("Waiting for new window...") - WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) - - # Get all window handles - all_windows = driver.window_handles - - print("Find the new window") - new_window = [window for window in all_windows if window != driver.current_window_handle][0] - - print("Switch to the new window") - driver.switch_to.window(new_window) - - wait = WebDriverWait(driver, 60) - - print("Wait for email input...") - email_field = wait.until(EC.presence_of_element_located((By.ID, ':r1:'))) - print("Enter email") - email_field.send_keys(EMAIL) - email_field.send_keys(Keys.RETURN) - - # Wait for the OTP to arrive and page to load - print("Wait for OTP...") - time.sleep(10) - - print("Get OTP from Gmail...") - code = fetch_code() - if code: - print(f"Successfully fetched OTP: {code}") - else: - print("Failed to fetch OTP from Gmail") - driver.quit() - - print("Find OTP input...") - otp_field = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[data-testid="passwordless_passcode__TextInput--0__input"]'))) - print("Enter OTP") - otp_field.send_keys(code) - - print("Wait for success page...") - success = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[data-testid="device_success_title"]'))) - print("Connected to Passport!") - - driver.quit() - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/sample/Tests/src/device_code_logout_windows.py b/sample/Tests/src/device_code_logout_windows.py deleted file mode 100644 index 385e56c3..00000000 --- a/sample/Tests/src/device_code_logout_windows.py +++ /dev/null @@ -1,33 +0,0 @@ - -from selenium import webdriver -from selenium.webdriver.chrome.service import Service -from selenium.webdriver.chrome.options import Options -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.keys import Keys - -def main(): - print("Connect to Chrome") - # Set up Chrome options to connect to the existing Chrome instance - chrome_options = Options() - chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") - # Connect to the existing Chrome instance - driver = webdriver.Chrome(options=chrome_options) - - print("Waiting for new window...") - WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) - - # Get all window handles - all_windows = driver.window_handles - - print("Find the new window") - new_window = [window for window in all_windows if window != driver.current_window_handle][0] - - print("Switch to the new window") - driver.switch_to.window(new_window) - - driver.quit() - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/sample/Tests/test/test.py b/sample/Tests/test/test.py index cda45fd3..7593d747 100644 --- a/sample/Tests/test/test.py +++ b/sample/Tests/test/test.py @@ -2,13 +2,14 @@ import unittest import requests import re +import pytest from alttester import * class TestConfig: - EMAIL = "a1369a61-9149-4499-a75e-610523e2baa7@mailslurp.net" - PASSPORT_ID="email|673a7cc7219c150ace38cf60" - WALLET_ADDRESS = "0xf629c9f0fee71cce1b21a6e5b0db8df2e8cd7354" + EMAIL = "26b067b8-ef3a-4655-955a-19f157b35b6e@mailslurp.net" + PASSPORT_ID="email|673d0795219c150acebff862" + WALLET_ADDRESS = "0x9af9826a83581ddfa0bdd7754de8a741ce64ebe8" class UnityTest(unittest.TestCase): @@ -22,6 +23,7 @@ def setUpClass(cls): def tearDownClass(cls): cls.altdriver.stop() + @pytest.mark.skip(reason="Base test should not be executed directly") def test_0_other_functions(self): # Show set call timeout scene self.altdriver.find_object(By.NAME, "CallTimeout").tap() @@ -37,6 +39,7 @@ def test_0_other_functions(self): self.altdriver.find_object(By.NAME, "CancelButton").tap() self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + @pytest.mark.skip(reason="Base test should not be executed directly") def test_1_passport_functions(self): output = self.altdriver.find_object(By.NAME, "Output") @@ -61,6 +64,7 @@ def test_1_passport_functions(self): time.sleep(1) self.assertEqual("No linked addresses", output.get_text()) + @pytest.mark.skip(reason="Base test should not be executed directly") def test_2_imx_functions(self): output = self.altdriver.find_object(By.NAME, "Output") @@ -75,20 +79,20 @@ def test_2_imx_functions(self): # Register off-chain # Wait up to 3 times for "Passport account already registered" to appear - #attempts = 0 - #while attempts < 6: - # self.altdriver.find_object(By.NAME, "RegisterOffchainBtn").tap() - # self.assertEqual("Registering off-chain...", output.get_text()) - # time.sleep(20) - # if "Passport account already registered" in output.get_text(): - # break - # attempts += 1 + attempts = 0 + while attempts < 3: + self.altdriver.find_object(By.NAME, "RegisterOffchainBtn").tap() + self.assertEqual("Registering off-chain...", output.get_text()) + time.sleep(20) + if "Passport account already registered" in output.get_text(): + break + attempts += 1 # Assert that the desired text is found after waiting - #self.assertTrue( - # "Passport account already registered" in output.get_text(), - # f"Expected 'Passport account already registered' not found. Actual output: '{output.get_text()}'" - #) + self.assertTrue( + "Passport account already registered" in output.get_text(), + f"Expected 'Passport account already registered' not found. Actual output: '{output.get_text()}'" + ) # Get address self.altdriver.find_object(By.NAME, "GetAddressBtn").tap() @@ -158,6 +162,7 @@ def test_2_imx_functions(self): self.altdriver.find_object(By.NAME, "CancelButton").tap() self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + @pytest.mark.skip(reason="Base test should not be executed directly") def test_3_zkevm_functions(self): output = self.altdriver.find_object(By.NAME, "Output") diff --git a/sample/Tests/test/test_device_code_logout.py b/sample/Tests/test/test_device_code_logout.py deleted file mode 100644 index beb6cb92..00000000 --- a/sample/Tests/test/test_device_code_logout.py +++ /dev/null @@ -1,25 +0,0 @@ -import time -import unittest - -from alttester import * - -class MacTest(unittest.TestCase): - - altdriver = None - - @classmethod - def setUpClass(cls): - cls.altdriver = AltDriver() - - @classmethod - def tearDownClass(cls): - cls.altdriver.stop() - - def test_5_logout(self): - # Logout - self.altdriver.find_object(By.NAME, "LogoutBtn").tap() - - time.sleep(10) - - # Wait for authenticated screen - self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") diff --git a/sample/Tests/test/test_mac.py b/sample/Tests/test/test_mac.py index bd18c6d5..ece728e0 100644 --- a/sample/Tests/test/test_mac.py +++ b/sample/Tests/test/test_mac.py @@ -1,18 +1,19 @@ import time -import unittest -import requests -import re from alttester import * -from test import TestConfig +from test import TestConfig, UnityTest +from test_mac_helpers import login, open_sample_app, bring_sample_app_to_foreground, stop_chrome, stop_sample_app -class MacTest(unittest.TestCase): + +class MacTest(UnityTest): altdriver = None @classmethod def setUpClass(cls): + open_sample_app + cls.altdriver = AltDriver() @classmethod @@ -27,48 +28,48 @@ def test_1_device_code_login(self): self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") # Login - loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn") - loginBtn.tap() - + print("Logging in...") + login() + bring_sample_app_to_foreground() + self.altdriver.wait_for_object(By.NAME, "LoginBtn").tap() # Wait for authenticated screen self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + print("Logged in") - def test_2_device_code_connect_imx(self): - # Select use device code auth - self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap() + def test_2_other_functions(self): + self.test_0_other_functions() - # Wait for unauthenticated screen - self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + def test_3_passport_functions(self): + self.test_1_passport_functions() - # Connect IMX - connectBtn = self.altdriver.wait_for_object(By.NAME, "ConnectBtn") - connectBtn.tap() + def test_4_imx_functions(self): + self.test_2_imx_functions() - # Wait for authenticated screen - self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + def test_5_zkevm_functions(self): + self.test_3_zkevm_functions() - # 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) + def test_6_device_code_relogin(self): + # Close and reopen app + stop_sample_app() + open_sample_app() - # 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()) + # Restart AltTester + self.altdriver.stop() + self.altdriver = AltDriver() + time.sleep(5) - def test_3_device_code_relogin(self): # Select use device code auth self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap() - # Wait for unauthenticated screen self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") # Relogin - reloginBtn = self.altdriver.wait_for_object(By.NAME, "ReloginBtn") - reloginBtn.tap() + 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() @@ -79,19 +80,30 @@ def test_3_device_code_relogin(self): self.altdriver.find_object(By.NAME, "ConnectBtn").tap() self.assertEqual("Connected to IMX", output.get_text()) - def test_4_device_code_reconnect(self): + self.altdriver.stop() + + def test_7_reconnect_device_code_connect_imx(self): + # Close and reopen app + stop_sample_app() + open_sample_app() + + # Restart AltTester + self.altdriver.stop() + self.altdriver = AltDriver() + time.sleep(5) + # Select use device code auth self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap() - # Wait for unauthenticated screen self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") - # Relogin - reloginBtn = self.altdriver.wait_for_object(By.NAME, "ReconnectBtn") - reloginBtn.tap() + # 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() @@ -102,11 +114,41 @@ def test_4_device_code_reconnect(self): self.altdriver.find_object(By.NAME, "GetAddressBtn").tap() self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text()) - def test_5_logout(self): # Logout + print("Logging out...") self.altdriver.find_object(By.NAME, "LogoutBtn").tap() + time.sleep(5) + bring_sample_app_to_foreground() + # Wait for authenticated screen + self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + stop_chrome() + print("Logged out") + + # Connect IMX + print("Logging in and connecting to IMX...") + self.altdriver.wait_for_object(By.NAME, "ConnectBtn").tap() + login() + bring_sample_app_to_foreground() + # Wait for authenticated screen + self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + print("Logged in and connected to IMX") + stop_chrome() + + # 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) - time.sleep(10) + # 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) + bring_sample_app_to_foreground() # Wait for authenticated screen - self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") \ No newline at end of file + self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + stop_chrome() + print("Logged out") \ No newline at end of file diff --git a/sample/Tests/src/device_code_login.py b/sample/Tests/test/test_mac_helpers.py similarity index 61% rename from sample/Tests/src/device_code_login.py rename to sample/Tests/test/test_mac_helpers.py index da7aa2ef..ab0570e2 100644 --- a/sample/Tests/src/device_code_login.py +++ b/sample/Tests/test/test_mac_helpers.py @@ -1,3 +1,9 @@ +import os +import sys +import subprocess +import time +from pathlib import Path + from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options @@ -6,11 +12,13 @@ from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys import time + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'src')) from fetch_otp import EMAIL, fetch_code # brew install chromedriver -def main(): +def login(): print("Connect to Chrome") # Set up Chrome options to connect to the existing Chrome instance chrome_options = Options() @@ -65,5 +73,39 @@ def main(): driver.quit() -if __name__ == "__main__": - main() \ No newline at end of file +def open_sample_app(): + print("Opening Unity sample app...") + subprocess.Popen(["open", "SampleApp.app"], shell=False) + time.sleep(5) + print("Unity sample app opened successfully.") + +def stop_sample_app(): + print("Stopping sample app...") + try: + # Get the PID of the sample app using ps, grep, and awk + cmd = f"ps aux | grep 'Sample.app' | grep -v grep | awk '{{print $2}}'" + pid = subprocess.check_output(cmd, shell=True, text=True).strip() + + if pid: + # Terminate the process using the PID + subprocess.run(["kill", pid]) + print(f"Sample app (PID {pid}) has been terminated.") + else: + print("Sample app is not running.") + except subprocess.CalledProcessError: + print("Failed to find the sample app process.") + + time.sleep(5) + print("Stopped sample app.") + +def bring_sample_app_to_foreground(app_name): + print("Bringing Unity sample app to the foreground...") + subprocess.run( + ['osascript', '-e', f'tell application "{app_name}" to activate'], + check=True + ) + +def stop_chrome(): + print("Stopping Chrome all Chrome instances...") + subprocess.run(["pkill", "-f", "chrome"], check=True) + print("Stopped Chrome.") \ No newline at end of file diff --git a/sample/Tests/test/test_windows.py b/sample/Tests/test/test_windows.py index e5124d67..d07cf3eb 100644 --- a/sample/Tests/test/test_windows.py +++ b/sample/Tests/test/test_windows.py @@ -1,72 +1,133 @@ import time -import unittest -import requests from alttester import * -from test import TestConfig +from test import TestConfig, UnityTest +from test_windows_helpers import login, open_sample_app, launch_chrome, bring_sample_app_to_foreground, stop_chrome, stop_sample_app -class WindowsTest(unittest.TestCase): +class WindowsTest(UnityTest): altdriver = None @classmethod def setUpClass(cls): + open_sample_app() + cls.altdriver = AltDriver() @classmethod def tearDownClass(cls): - cls.altdriver.stop() + cls.altdriver.stop() def test_1_device_code_login(self): - # Login - loginBtn = self.altdriver.wait_for_object(By.NAME, "LoginBtn") - loginBtn.tap() + launch_chrome() + + bring_sample_app_to_foreground() + self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + + # Login + print("Logging in...") + self.altdriver.wait_for_object(By.NAME, "LoginBtn").tap() + login() + bring_sample_app_to_foreground() # Wait for authenticated screen self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + print("Logged in") - def test_2_device_code_connect_imx(self): - # Connect IMX - connectBtn = self.altdriver.wait_for_object(By.NAME, "ConnectBtn") - connectBtn.tap() + stop_chrome() + + def test_2_other_functions(self): + self.test_0_other_functions() + + def test_3_passport_functions(self): + self.test_1_passport_functions() + + def test_4_imx_functions(self): + self.test_2_imx_functions() + + def test_5_zkevm_functions(self): + self.test_3_zkevm_functions() + + def test_6_relogin(self): + # Close and reopen app + stop_sample_app() + open_sample_app() + + # Restart AltTester + self.altdriver.stop() + self.altdriver = AltDriver() + time.sleep(5) + + # 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) - # 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()) + # Click Connect to IMX button + self.altdriver.find_object(By.NAME, "ConnectBtn").tap() + self.assertEqual("Connected to IMX", output.get_text()) - def test_3_device_code_relogin(self): - # Relogin - reloginBtn = self.altdriver.wait_for_object(By.NAME, "ReloginBtn") - reloginBtn.tap() + self.altdriver.stop() + + def test_7_reconnect_device_code_connect_imx(self): + # Close and reopen app + stop_sample_app() + open_sample_app() + + # Restart AltTester + self.altdriver.stop() + self.altdriver = AltDriver() + time.sleep(5) + + # 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) - # Click Connect to IMX button - self.altdriver.find_object(By.NAME, "ConnectBtn").tap() - self.assertEqual("Connected to IMX", output.get_text()) + # 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()) - def test_4_device_code_reconnect(self): - # Relogin - reloginBtn = self.altdriver.wait_for_object(By.NAME, "ReconnectBtn") - reloginBtn.tap() + # Logout + print("Logging out...") + launch_chrome() + bring_sample_app_to_foreground() + self.altdriver.find_object(By.NAME, "LogoutBtn").tap() + time.sleep(5) + bring_sample_app_to_foreground() + # Wait for authenticated screen + self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + stop_chrome() + print("Logged out") + # Connect IMX + print("Logging in and connecting to IMX...") + launch_chrome() + bring_sample_app_to_foreground() + self.altdriver.wait_for_object(By.NAME, "ConnectBtn").tap() + login() + bring_sample_app_to_foreground() # Wait for authenticated screen self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene") + print("Logged in and connected to IMX") + stop_chrome() # Get access token self.altdriver.find_object(By.NAME, "GetAccessTokenBtn").tap() @@ -76,3 +137,15 @@ def test_4_device_code_reconnect(self): # 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 + launch_chrome() + bring_sample_app_to_foreground() + print("Logging out...") + self.altdriver.find_object(By.NAME, "LogoutBtn").tap() + time.sleep(5) + bring_sample_app_to_foreground() + # Wait for authenticated screen + self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene") + stop_chrome() + print("Logged out") diff --git a/sample/Tests/test/test_windows_helpers.py b/sample/Tests/test/test_windows_helpers.py new file mode 100644 index 00000000..269b645e --- /dev/null +++ b/sample/Tests/test/test_windows_helpers.py @@ -0,0 +1,151 @@ +import os +import sys +import subprocess +import time +from pathlib import Path + +from selenium import webdriver +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.keys import Keys + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'src')) +from fetch_otp import EMAIL, fetch_code + +# Add chrome.exe to environment variable +# Download chrome driver and add to environment variable + +def login(): + print("Connect to Chrome") + # Set up Chrome options to connect to the existing Chrome instance + chrome_options = Options() + chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") + # Connect to the existing Chrome instance + driver = webdriver.Chrome(options=chrome_options) + + print("Open a window on Chrome") + # Get the original window handle + original_window = driver.current_window_handle + + print("Waiting for new window...") + WebDriverWait(driver, 60).until(EC.number_of_windows_to_be(2)) + + # Get all window handles + all_windows = driver.window_handles + + print("Find the new window") + new_window = [window for window in all_windows if window != driver.current_window_handle][0] + + print("Switch to the new window") + driver.switch_to.window(new_window) + + wait = WebDriverWait(driver, 60) + + print("Wait for email input...") + email_field = wait.until(EC.presence_of_element_located((By.ID, ':r1:'))) + print("Enter email") + email_field.send_keys(EMAIL) + email_field.send_keys(Keys.RETURN) + + # Wait for the OTP to arrive and page to load + print("Wait for OTP...") + time.sleep(10) + + print("Get OTP from Gmail...") + code = fetch_code() + if code: + print(f"Successfully fetched OTP: {code}") + else: + print("Failed to fetch OTP from Gmail") + driver.quit() + + print("Find OTP input...") + otp_field = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[data-testid="passwordless_passcode__TextInput--0__input"]'))) + print("Enter OTP") + otp_field.send_keys(code) + + print("Wait for success page...") + success = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[data-testid="device_success_title"]'))) + print("Connected to Passport!") + + driver.quit() + +def open_sample_app(): + print("Opening Unity sample app...") + subprocess.Popen(["SampleApp.exe"], shell=True) + time.sleep(10) + print("Unity sample app opened successfully.") + +def stop_sample_app(): + print("Stopping sample app...") + powershell_command = """ + $process = Get-Process -Name "SampleApp" -ErrorAction SilentlyContinue + if ($process) { + Stop-Process -Id $process.Id + Write-Output "SampleApp.exe has been closed." + } else { + Write-Output "SampleApp.exe is not running." + } + """ + subprocess.run(["powershell.exe", "-Command", powershell_command], check=True) + time.sleep(5) + print("Stopped sample app.") + +def bring_sample_app_to_foreground(): + powershell_script_path = "./switch-app.ps1" + + print("Bring Unity sample app to the foreground.") + + command = [ + "powershell.exe", + "-Command", + f"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '{powershell_script_path}' -appName 'Immutable Sample'" + ] + + subprocess.run(command, check=True) + time.sleep(10) + +def launch_chrome(): + print("Starting Chrome...") + chrome_paths = [ + r"C:\Program Files\Google\Chrome\Application\chrome.exe", + r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" + ] + + chrome_path = None + for path in chrome_paths: + if os.path.exists(path): + chrome_path = path + break + + if not chrome_path: + print("Chrome executable not found.") + exit(1) + + subprocess.run([ + "powershell.exe", + "-Command", + f"Start-Process -FilePath '{chrome_path}' -ArgumentList '--remote-debugging-port=9222'" + ], check=True) + + time.sleep(5) + +def stop_chrome(): + print("Stopping Chrome...") + powershell_command = """ + $process = Get-Process -Name "chrome" -ErrorAction SilentlyContinue + if ($process) { + $process | ForEach-Object { + Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue + } + Write-Output "All Chrome processes have been closed." + } else { + Write-Output "Chrome is not running." + } + """ + subprocess.run(["powershell.exe", "-Command", powershell_command], check=True) + time.sleep(5) + print("Stopped Chrome.") \ No newline at end of file diff --git a/sample/Tests/test_windows.ps1 b/sample/Tests/test_windows.ps1 deleted file mode 100644 index a1aa5787..00000000 --- a/sample/Tests/test_windows.ps1 +++ /dev/null @@ -1,191 +0,0 @@ -# Function to stop the Unity sample app if it's running -function Stop-SampleApp { - $process = Get-Process -Name "SampleApp" -ErrorAction SilentlyContinue - if ($process) { - Stop-Process -Id $process.Id - Write-Output "SampleApp.exe has been closed." - } else { - Write-Output "SampleApp.exe is not running." - } - Start-Sleep -Seconds 5 -} - -# Function to start the Unity sample app -function Start-SampleApp { - Write-Output "Starting Unity sample app..." - Start-Process -FilePath "SampleApp.exe" - Start-Sleep -Seconds 10 -} - -# Function to bring the Unity sample app to the foreground -function Bring-SampleAppToForeground { - $POWERSHELL_SCRIPT_PATH = "./switch-app.ps1" - Write-Output "Bringing Unity sample app to the foreground..." - powershell.exe -Command "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '$POWERSHELL_SCRIPT_PATH' -appName 'Immutable Sample'" -} - -# Function to run pytest tests -function Run-Pytest { - param ( - [string]$testFile - ) - Write-Output "Running pytest for $testFile..." - $process = Start-Process -FilePath "pytest" -ArgumentList "-x", $testFile -NoNewWindow -PassThru -Wait - if ($process.ExitCode -ne 0) { - Write-Output "Test failed for $testFile. Stopping execution." - exit $process.ExitCode - } -} - -# Function to stop Chrome if it's running -function Stop-Chrome { - Write-Output "Stopping Chrome.." - $process = Get-Process -Name "chrome" -ErrorAction SilentlyContinue - if ($process) { - $process | ForEach-Object { - Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue - } - Write-Output "All Chrome processes have been closed." - } else { - Write-Output "Chrome is not running." - } - - Start-Sleep -Seconds 10 -} - -# Login -function Login { - param ( - [string]$testFile - ) - # Start Chrome for remote debugging - Write-Output "Starting Chrome..." - - $chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe" - - if (-not (Test-Path $chromePath)) { - $chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" - } - - if (-not (Test-Path $chromePath)) { - Write-Output "Chrome executable not found." - exit - } - - Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222" - - # Run Python script for login - Write-Output "Running python script to login..." - $pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_login_windows.py" -NoNewWindow -PassThru - Write-Output "Python script running in the background..." - - Start-Sleep -Seconds 5 - - Bring-SampleAppToForeground - - Write-Output "Running login test..." - $pytestProcess = Start-Process -FilePath "pytest" -ArgumentList $testFile -NoNewWindow -PassThru - - $pythonProcess | Wait-Process - - Bring-SampleAppToForeground - - $pytestProcess | Wait-Process - - Stop-Chrome -} - -# Logout -function Logout { - # Start Chrome for remote debugging - Write-Output "Starting Chrome..." - $chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe" - - if (-not (Test-Path $chromePath)) { - $chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" - } - - if (-not (Test-Path $chromePath)) { - Write-Output "Chrome executable not found." - exit - } - - Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222" - - Write-Output "Running python script to logout..." - $pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_logout_windows.py" -NoNewWindow -PassThru - Start-Sleep -Seconds 5 - - Bring-SampleAppToForeground - - Write-Output "Running logout test..." - $pytestProcess = Start-Process -FilePath "pytest" -ArgumentList "test/test_device_code_logout.py" -NoNewWindow -PassThru - - $pythonProcess | Wait-Process - - Bring-SampleAppToForeground - - $pytestProcess | Wait-Process - - Stop-Chrome -} - -# Capture the start time -$startTime = Get-Date - -# Start Unity sample app -Start-SampleApp - -# Login -Login "test/test_windows.py::WindowsTest::test_1_device_code_login" - -# Run IMX and zkEVM tests -Run-Pytest "test/test.py" -if (-not $?) { - Write-Output "Tests failed. Stopping execution." - exit 1 -} - -# Relogin -Stop-SampleApp -Start-SampleApp -Run-Pytest "test/test_windows.py::WindowsTest::test_3_device_code_relogin" -if (-not $?) { - Write-Output "Relogin test failed. Stopping execution." - exit 1 -} - -# Reconnect -Stop-SampleApp -Start-SampleApp -Run-Pytest "test/test_windows.py::WindowsTest::test_4_device_code_reconnect" -if (-not $?) { - Write-Output "Reconnect test failed. Stopping execution." - exit 1 -} - -# Logout -Logout - -# Connect IMX -Stop-SampleApp -Start-SampleApp -Write-Output "Connect to IMX..." -Login "test/test_windows.py::WindowsTest::test_2_device_code_connect_imx" - -# Bring the Unity sample app to the foreground -Bring-SampleAppToForeground - -# Logout -Logout - -# Final stop of Unity sample app -Stop-SampleApp - -# Capture the end time -$endTime = Get-Date - -# Calculate and display the elapsed time -$elapsedTime = $endTime - $startTime -Write-Output "All tests completed." -Write-Output "Elapsed time: $($elapsedTime.TotalMinutes) minutes" \ No newline at end of file