Skip to content

Commit ddbff67

Browse files
committed
test: mac pkce ui test
1 parent 86e8c4b commit ddbff67

File tree

12 files changed

+120
-88
lines changed

12 files changed

+120
-88
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ sample/Assets/Vuplex*
107107

108108
__pycache__/
109109
*.pyc
110-
.pytest_cache/
110+
.pytest_cache/
111+
112+
xcuserdata/

Plugins/Mac/Sources/ImmutableWebView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,5 @@ void _CImmutableWebViewPlugin_LaunchAuthURL(void *instance, const char *url, con
424424
if (instance == NULL)
425425
return;
426426
CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance;
427-
[webViewPlugin launchAuthURL:url redirectUri: redirectUri];
427+
[webViewPlugin launchAuthURL:url redirectUri:redirectUri];
428428
}

Plugins/Mac/install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ mkdir -p $DSTDIR
66

77
cp -r DerivedData/ImmutableWebView.bundle $DSTDIR
88
rm -rf DerivedData
9-
cp *.bundle.meta $DSTDIR

sample/Assets/Editor/MacBuilder.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptio
3838
{
3939
// Clean up AltTester settings after build
4040
AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone);
41+
42+
// Clean up custom e2e testing define
43+
var defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
44+
defineSymbols = defineSymbols.Replace("IMMUTABLE_E2E_TESTING;", "").Replace(";IMMUTABLE_E2E_TESTING", "").Replace("IMMUTABLE_E2E_TESTING", "");
45+
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defineSymbols);
46+
4147
RemoveAltFromScene(buildPlayerOptions.scenes[0]);
4248
}
4349
}
@@ -66,7 +72,7 @@ private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, Bui
6672
{
6773
scenes = new[]
6874
{
69-
"Assets/Scenes/Passport/SelectAuthMethod.unity",
75+
"Assets/Scenes/Passport/Initialisation.unity",
7076
"Assets/Scenes/Passport/UnauthenticatedScene.unity",
7177
"Assets/Scenes/Passport/AuthenticatedScene.unity",
7278
"Assets/Scenes/Passport/ZkEvm/ZkEvmGetBalance.unity",
@@ -85,6 +91,15 @@ private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, Bui
8591
private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions)
8692
{
8793
AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Standalone);
94+
95+
// Add custom define for e2e testing to enable default browser behavior
96+
var defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
97+
if (!defineSymbols.Contains("IMMUTABLE_E2E_TESTING"))
98+
{
99+
defineSymbols += ";IMMUTABLE_E2E_TESTING";
100+
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defineSymbols);
101+
}
102+
88103
AltBuilder.CreateJsonFileForInputMappingOfAxis();
89104

90105
var instrumentationSettings = new AltInstrumentationSettings();

sample/Assets/Editor/MobileBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, Bui
117117
{
118118
scenes = new[]
119119
{
120-
"Assets/Scenes/Passport/SelectAuthMethod.unity",
120+
"Assets/Scenes/Passport/Initialisation.unity",
121121
"Assets/Scenes/Passport/UnauthenticatedScene.unity",
122122
"Assets/Scenes/Passport/AuthenticatedScene.unity",
123123
"Assets/Scenes/Passport/ZkEvm/ZkEvmGetBalance.unity",

sample/Assets/Editor/WindowsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, Bui
6666
{
6767
scenes = new[]
6868
{
69-
"Assets/Scenes/Passport/SelectAuthMethod.unity",
69+
"Assets/Scenes/Passport/Initialisation.unity",
7070
"Assets/Scenes/Passport/UnauthenticatedScene.unity",
7171
"Assets/Scenes/Passport/AuthenticatedScene.unity",
7272
"Assets/Scenes/Passport/ZkEvm/ZkEvmGetBalance.unity",

sample/Assets/Scenes/Passport/Initialisation.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ MonoBehaviour:
11281128
m_TargetGraphic: {fileID: 167431872}
11291129
m_HandleRect: {fileID: 167431871}
11301130
m_Direction: 2
1131-
m_Value: 1
1131+
m_Value: 0
11321132
m_Size: 1
11331133
m_NumberOfSteps: 0
11341134
m_OnValueChanged:
@@ -1398,8 +1398,8 @@ RectTransform:
13981398
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
13991399
m_AnchorMin: {x: 0, y: 0}
14001400
m_AnchorMax: {x: 0, y: 0}
1401-
m_AnchoredPosition: {x: 1108.9248, y: 0}
1402-
m_SizeDelta: {x: 2177.8496, y: 0}
1401+
m_AnchoredPosition: {x: 1801.0891, y: 0}
1402+
m_SizeDelta: {x: 3562.1782, y: 0}
14031403
m_Pivot: {x: 0.5, y: 0.5}
14041404
--- !u!114 &1661390145
14051405
MonoBehaviour:

sample/Assets/Scripts/Passport/Login/LoginScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public async void Login()
3333
await Passport.Login();
3434
SceneManager.LoadScene("AuthenticatedScene");
3535
}
36-
catch (OperationCanceledException)
36+
catch (OperationCanceledException ex)
3737
{
38-
ShowOutput("Failed to login: cancelled");
38+
ShowOutput($"Failed to login: cancelled {ex.Message}\\n{ex.StackTrace}");
3939
}
4040
catch (Exception ex)
4141
{

sample/ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ PlayerSettings:
7676
androidFullscreenMode: 1
7777
defaultIsNativeResolution: 1
7878
macRetinaSupport: 0
79-
runInBackground: 0
79+
runInBackground: 1
8080
captureSingleScreen: 0
8181
muteOtherAudioSources: 0
8282
Prepare IOS For Recording: 0
@@ -222,7 +222,8 @@ PlayerSettings:
222222
iOSDeviceRequirements: []
223223
iOSURLSchemes:
224224
- immutablerunner
225-
macOSURLSchemes: []
225+
macOSURLSchemes:
226+
- immutablerunner
226227
iOSBackgroundModes: 0
227228
iOSMetalForceHardShadows: 0
228229
metalEditorSupport: 1

sample/Tests/test/test_mac.py

Lines changed: 86 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22
import time
3+
import os
4+
import subprocess
35
from pathlib import Path
46

57
from selenium import webdriver
@@ -21,44 +23,81 @@
2123
class MacTest(UnityTest):
2224

2325
altdriver = None
24-
seleniumdriver = None
2526

2627
@classmethod
2728
def setUpClass(cls):
2829
open_sample_app()
2930
cls.altdriver = AltDriver()
31+
cls.stop_browser()
3032

3133
@classmethod
3234
def tearDownClass(cls):
3335
stop_sample_app()
3436
cls.altdriver.stop()
37+
cls.stop_browser()
3538

3639
@classmethod
37-
def setupChrome(cls):
38-
print("Connect to Chrome")
39-
chrome_options = Options()
40-
chrome_options.add_argument('--remote-debugging-port=9222')
40+
def launch_browser(cls):
41+
print("Starting Browser...")
42+
browser_paths = [
43+
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
44+
]
45+
46+
browser_path = None
47+
for path in browser_paths:
48+
if os.path.exists(path):
49+
browser_path = path
50+
break
51+
52+
if not browser_path:
53+
print("Brave executable not found.")
54+
exit(1)
55+
56+
subprocess.Popen([
57+
browser_path,
58+
"--remote-debugging-port=9222"
59+
])
4160

42-
# Initialise Chrome driver
43-
cls.seleniumdriver = webdriver.Chrome(options=chrome_options)
61+
time.sleep(5)
4462

45-
print("Open a window on Chrome")
46-
cls.seleniumdriver.current_window_handle
63+
@classmethod
64+
def stop_browser(cls):
65+
print("Stopping Brave...")
66+
try:
67+
# First try graceful shutdown using AppleScript
68+
subprocess.run([
69+
"osascript", "-e",
70+
'tell application "Brave Browser" to quit'
71+
], check=False, capture_output=True)
72+
time.sleep(2)
73+
74+
# Check if still running, then force kill
75+
result = subprocess.run(["pgrep", "-f", "Brave Browser"],
76+
capture_output=True, text=True)
77+
if result.returncode == 0:
78+
# Still running, force kill
79+
subprocess.run(["pkill", "-f", "Brave Browser"],
80+
check=False, capture_output=True)
81+
82+
print("All Brave processes have been closed.")
83+
except Exception as e:
84+
print("Brave might not be running.")
85+
86+
time.sleep(3)
87+
print("Stopped Brave")
4788

4889
@classmethod
4990
def login(cls):
50-
print("Waiting for new window...")
51-
WebDriverWait(cls.seleniumdriver, 30).until(EC.number_of_windows_to_be(2))
91+
print("Connect to Chrome")
92+
# Set up Chrome options to connect to the existing Chrome instance
93+
chrome_options = Options()
94+
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
95+
# Connect to the existing Chrome instance
96+
cls.seleniumdriver = webdriver.Chrome(options=chrome_options)
5297

53-
# Switch to the new window
54-
all_windows = cls.seleniumdriver.window_handles
55-
new_window = [window for window in all_windows if window != cls.seleniumdriver.current_window_handle][0]
56-
cls.seleniumdriver.switch_to.window(new_window)
57-
print("Switched to new window")
98+
print("Open a window on Chrome")
5899

59-
## Device confirmation
60-
contine_button = WebDriverWait(cls.seleniumdriver, 60).until(EC.element_to_be_clickable((SeleniumBy.XPATH, "//button[span[text()='Continue']]")))
61-
contine_button.click()
100+
wait = WebDriverWait(cls.seleniumdriver, 60)
62101

63102
# Wait for email input and enter email
64103
email_field = WebDriverWait(cls.seleniumdriver, 60).until(EC.presence_of_element_located((SeleniumBy.ID, ':r1:')))
@@ -83,16 +122,23 @@ def login(cls):
83122
print("Entering OTP...")
84123
otp_field.send_keys(code)
85124

86-
# Wait for success page and confirm
87-
success = WebDriverWait(cls.seleniumdriver, 60).until(EC.presence_of_element_located((SeleniumBy.CSS_SELECTOR, 'h1[data-testid="device_success_title"]')))
88-
print("Connected to Passport!")
89-
125+
time.sleep(5)
126+
90127
cls.seleniumdriver.quit()
91128

92-
def test_1_device_code_login(self):
93-
# Select use device code auth
94-
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()
129+
@classmethod
130+
def logout(cls):
131+
print("Logging out...")
132+
cls.launch_browser()
133+
bring_sample_app_to_foreground()
134+
cls.altdriver.find_object(By.NAME, "LogoutBtn").tap()
135+
time.sleep(5)
136+
cls.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
137+
time.sleep(2)
138+
cls.stop_browser()
139+
print("Logged out")
95140

141+
def test_1_login(self):
96142
# Wait for unauthenticated screen
97143
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
98144

@@ -104,15 +150,16 @@ def test_1_device_code_login(self):
104150

105151
# Login
106152
print("Logging in...")
107-
self.setupChrome()
153+
self.launch_browser()
108154
bring_sample_app_to_foreground()
109155
login_button.tap()
110156
self.login()
111-
bring_sample_app_to_foreground()
112157

113158
# Wait for authenticated screen
114159
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
115160
print("Logged in")
161+
162+
self.stop_browser()
116163
return
117164
except Exception as err:
118165
if attempt == 0:
@@ -127,16 +174,7 @@ def test_1_device_code_login(self):
127174
print("Re-logged in")
128175

129176
# Logout
130-
print("Logging out...")
131-
self.setupChrome()
132-
bring_sample_app_to_foreground()
133-
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
134-
time.sleep(5)
135-
bring_sample_app_to_foreground()
136-
137-
# Wait for unauthenticated screen
138-
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
139-
self.seleniumdriver.quit()
177+
self.logout()
140178
print("Logged out and successfully reset app")
141179

142180
time.sleep(5)
@@ -155,18 +193,16 @@ def test_4_imx_functions(self):
155193
def test_5_zkevm_functions(self):
156194
self.test_3_zkevm_functions()
157195

158-
def test_6_device_code_relogin(self):
196+
def test_6_relogin(self):
159197
# Close and reopen app
160198
stop_sample_app()
161199
open_sample_app()
162200

163201
# Restart AltTester
164202
self.altdriver.stop()
165-
self.altdriver = AltDriver()
203+
self.__class__.altdriver = AltDriver()
166204
time.sleep(5)
167205

168-
# Select use device code auth
169-
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()
170206
# Wait for unauthenticated screen
171207
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
172208

@@ -189,18 +225,16 @@ def test_6_device_code_relogin(self):
189225

190226
self.altdriver.stop()
191227

192-
def test_7_reconnect_device_code_connect_imx(self):
228+
def test_7_reconnect_connect_imx(self):
193229
# Close and reopen app
194230
stop_sample_app()
195231
open_sample_app()
196232

197233
# Restart AltTester
198234
self.altdriver.stop()
199-
self.altdriver = AltDriver()
235+
self.__class__.altdriver = AltDriver()
200236
time.sleep(5)
201237

202-
# Select use device code auth
203-
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()
204238
# Wait for unauthenticated screen
205239
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
206240

@@ -222,28 +256,19 @@ def test_7_reconnect_device_code_connect_imx(self):
222256
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())
223257

224258
# Logout
225-
print("Logging out...")
226-
self.setupChrome()
227-
bring_sample_app_to_foreground()
228-
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
229-
time.sleep(5)
230-
bring_sample_app_to_foreground()
231-
232-
# Wait for authenticated screen
233-
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
234-
self.seleniumdriver.quit()
235-
print("Logged out")
259+
self.logout()
236260

237261
# Connect IMX
262+
time.sleep(5)
238263
print("Logging in and connecting to IMX...")
239-
self.setupChrome()
264+
self.launch_browser()
240265
bring_sample_app_to_foreground()
241266
self.altdriver.wait_for_object(By.NAME, "ConnectBtn").tap()
242267
self.login()
243-
bring_sample_app_to_foreground()
244268

245-
# Wait for authenticated screen
246269
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
270+
271+
self.stop_browser()
247272
print("Logged in and connected to IMX")
248273

249274
# Get access token
@@ -256,14 +281,4 @@ def test_7_reconnect_device_code_connect_imx(self):
256281
self.assertEqual(TestConfig.WALLET_ADDRESS, output.get_text())
257282

258283
# Logout
259-
print("Logging out...")
260-
self.setupChrome()
261-
bring_sample_app_to_foreground()
262-
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
263-
time.sleep(5)
264-
bring_sample_app_to_foreground()
265-
266-
# Wait for authenticated screen
267-
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
268-
self.seleniumdriver.quit()
269-
print("Logged out")
284+
self.logout()

0 commit comments

Comments
 (0)