Skip to content

Commit 917e233

Browse files
committed
feat(tests): add CI-friendly protocol dialog automation
- Add CI environment detection for GitHub Actions - Enhanced browser flags for CI automation - Automatic protocol dialog detection and clicking - Unity log monitoring for authentication success verification - Fallback handling for environments without protocol association This enables fully automated deep link handling in CI environments where manual 'Always allow' clicking is not possible.
1 parent 72b0e02 commit 917e233

1 file changed

Lines changed: 109 additions & 8 deletions

File tree

sample/Tests/test/test_windows_helpers.py

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,84 @@ def login():
127127
# Give a moment for any page transitions to complete
128128
time.sleep(3)
129129

130-
# With protocol association configured, deep link should execute automatically
131-
print("Protocol association configured - deep link should execute automatically")
132-
print("Waiting for Unity to receive the deep link callback...")
130+
# Handle deep link processing based on environment
131+
is_ci = os.getenv('CI') or os.getenv('GITHUB_ACTIONS') or os.getenv('BUILD_ID')
133132

134-
# Give Unity time to receive and process the deep link
135-
time.sleep(5)
136-
print("Deep link processing complete - authentication should be successful")
133+
if is_ci:
134+
print("CI environment - checking if authentication completed automatically")
135+
# In CI, the browser window may close immediately if auth succeeds
136+
# Check Unity logs to see if authentication was successful
137+
print("Monitoring Unity logs for authentication completion...")
138+
139+
auth_success = False
140+
for check_attempt in range(30): # Check for 30 seconds
141+
try:
142+
with open("C:\\Users\\WindowsBuildsdkServi\\AppData\\LocalLow\\Immutable\\Immutable Sample\\Player.log", 'r', encoding='utf-8', errors='ignore') as f:
143+
content = f.read()
144+
# Look for signs of successful authentication
145+
if any(phrase in content for phrase in [
146+
"AuthenticatedScene",
147+
"authentication successful",
148+
"logged in successfully",
149+
"Passport token received"
150+
]):
151+
print("Authentication success detected in Unity logs!")
152+
auth_success = True
153+
break
154+
except:
155+
pass
156+
time.sleep(1)
157+
158+
if not auth_success:
159+
print("No authentication success detected - attempting automated dialog handling")
160+
print("Looking for protocol permission dialog to click automatically...")
161+
162+
# Try to find and click the protocol dialog automatically
163+
try:
164+
ps_script = '''
165+
for ($i = 0; $i -lt 10; $i++) {
166+
$windows = Get-Process | Where-Object { $_.MainWindowTitle -like "*auth.immutable.com*" -or $_.MainWindowTitle -like "*Open*" }
167+
foreach ($window in $windows) {
168+
try {
169+
Add-Type -AssemblyName UIAutomationClient
170+
$element = [Windows.Automation.AutomationElement]::FromHandle($window.MainWindowHandle)
171+
if ($element) {
172+
$buttons = $element.FindAll([Windows.Automation.TreeScope]::Descendants,
173+
[Windows.Automation.Condition]::new([Windows.Automation.AutomationElement]::ControlTypeProperty,
174+
[Windows.Automation.ControlType]::Button))
175+
foreach ($button in $buttons) {
176+
$buttonText = $button.Current.Name
177+
if ($buttonText -like "*Open*" -or $buttonText -like "*Allow*" -or $buttonText -like "*Yes*") {
178+
$button.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern).Invoke()
179+
Write-Host "Clicked protocol dialog button: $buttonText"
180+
exit 0
181+
}
182+
}
183+
}
184+
} catch {}
185+
}
186+
Start-Sleep 1
187+
}
188+
Write-Host "No protocol dialog found"
189+
'''
190+
191+
result = subprocess.run(["powershell", "-Command", ps_script],
192+
capture_output=True, text=True, timeout=15)
193+
if "Clicked protocol dialog" in result.stdout:
194+
print("Successfully automated protocol dialog click in CI!")
195+
# Wait a bit more for Unity to process
196+
time.sleep(5)
197+
else:
198+
print("Could not find protocol dialog to automate")
199+
except Exception as e:
200+
print(f"CI dialog automation error: {e}")
201+
print("Protocol dialog may require manual setup in CI environment")
202+
203+
else:
204+
print("Local environment - protocol association should work automatically")
205+
print("Waiting for Unity to receive the deep link callback...")
206+
time.sleep(5)
207+
print("Deep link processing complete - authentication should be successful")
137208

138209
return # Exit function since we're done
139210
else:
@@ -389,11 +460,41 @@ def launch_browser():
389460
print("Brave executable not found.")
390461
exit(1)
391462

392-
# Launch Brave with additional flags to allow external protocol handling
463+
# Launch Brave with CI-friendly flags to handle protocol dialogs automatically
464+
browser_args = [
465+
'--remote-debugging-port=9222',
466+
'--disable-web-security',
467+
'--allow-running-insecure-content',
468+
'--disable-features=VizDisplayCompositor',
469+
'--disable-popup-blocking',
470+
'--no-first-run',
471+
'--disable-default-apps',
472+
'--disable-extensions',
473+
'--disable-component-extensions-with-background-pages',
474+
'--autoplay-policy=no-user-gesture-required',
475+
'--allow-external-protocol-handlers',
476+
'--enable-automation',
477+
'--disable-background-timer-throttling',
478+
'--disable-backgrounding-occluded-windows',
479+
'--disable-renderer-backgrounding'
480+
]
481+
482+
# Check if we're in CI environment
483+
is_ci = os.getenv('CI') or os.getenv('GITHUB_ACTIONS') or os.getenv('BUILD_ID')
484+
if is_ci:
485+
print("CI environment detected - adding additional protocol handling flags")
486+
browser_args.extend([
487+
'--disable-prompt-on-repost',
488+
'--disable-hang-monitor',
489+
'--disable-ipc-flooding-protection',
490+
'--force-permission-policy-unload-default-enabled'
491+
])
492+
493+
args_string = "', '".join(browser_args)
393494
result = subprocess.run([
394495
"powershell.exe",
395496
"-Command",
396-
f"$process = Start-Process -FilePath '{browser_path}' -ArgumentList '--remote-debugging-port=9222', '--disable-web-security', '--allow-running-insecure-content', '--disable-features=VizDisplayCompositor', '--external-auth-disable-prompt' -PassThru; Write-Output $process.Id"
497+
f"$process = Start-Process -FilePath '{browser_path}' -ArgumentList '{args_string}' -PassThru; Write-Output $process.Id"
397498
], capture_output=True, text=True, check=True)
398499

399500
# Store the debug browser process ID globally for later use

0 commit comments

Comments
 (0)