Skip to content

Commit 9d77d08

Browse files
committed
test: improve windows deeplink in test
1 parent bd6efad commit 9d77d08

2 files changed

Lines changed: 59 additions & 54 deletions

File tree

sample/Tests/test/test_windows.py

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -81,53 +81,38 @@ def login(self):
8181
raise SystemExit(f"App stuck in unknown scene: {current_scene}")
8282

8383
def _perform_login(self):
84-
"""Perform normal login flow when app is in UnauthenticatedScene"""
85-
try:
86-
# Debug: Check what scene we're actually in and what objects exist
84+
"""Perform normal login flow when app is in UnauthenticatedScene.
85+
Retries once if the first attempt fails (e.g. deep link dialog not handled)."""
86+
for attempt in range(2):
8787
try:
8888
current_scene = self.get_altdriver().get_current_scene()
89-
print(f"DEBUG: _perform_login - current scene: {current_scene}")
90-
except Exception as e:
91-
print(f"DEBUG: Could not get current scene: {e}")
92-
93-
# Wait a moment for UI to stabilize and check if app is still running
94-
time.sleep(3)
95-
96-
# Debug: Check if we can still communicate with the app
97-
try:
98-
connection_test = self.get_altdriver().get_current_scene()
99-
print(f"DEBUG: App still responsive, scene: {connection_test}")
100-
except Exception as e:
101-
print(f"DEBUG: App may have crashed or lost connection: {e}")
102-
raise SystemExit("App connection lost during login attempt")
103-
104-
# Debug: Try to find any buttons to see what's available
105-
try:
106-
all_objects = self.get_altdriver().get_all_elements()
107-
button_objects = [obj for obj in all_objects if 'btn' in obj.name.lower() or 'button' in obj.name.lower()]
108-
print(f"DEBUG: Found button-like objects: {[obj.name for obj in button_objects]}")
109-
except Exception as e:
110-
print(f"DEBUG: Could not get all objects: {e}")
111-
112-
# Check for login button
113-
login_button = self.get_altdriver().find_object(By.NAME, "LoginBtn")
114-
print("Found login button - performing login")
115-
116-
# Login
117-
launch_browser()
118-
bring_sample_app_to_foreground()
119-
login_button.tap()
120-
login()
121-
bring_sample_app_to_foreground()
122-
123-
# Wait for authenticated screen
124-
self.get_altdriver().wait_for_current_scene_to_be("AuthenticatedScene")
125-
stop_browser()
126-
print("[SUCCESS] Login successful")
127-
128-
except Exception as err:
129-
stop_browser()
130-
raise SystemExit(f"Login failed: {err}")
89+
print(f"Login attempt {attempt + 1}/2 - current scene: {current_scene}")
90+
91+
time.sleep(3)
92+
93+
login_button = self.get_altdriver().find_object(By.NAME, "LoginBtn")
94+
print("Found login button - performing login")
95+
96+
launch_browser()
97+
bring_sample_app_to_foreground()
98+
login_button.tap()
99+
login()
100+
bring_sample_app_to_foreground()
101+
102+
self.get_altdriver().wait_for_current_scene_to_be("AuthenticatedScene", timeout=30)
103+
stop_browser()
104+
print("[SUCCESS] Login successful")
105+
return
106+
107+
except Exception as err:
108+
stop_browser()
109+
if attempt == 0:
110+
print(f"Login attempt 1 failed: {err}")
111+
print("Retrying login...")
112+
time.sleep(5)
113+
bring_sample_app_to_foreground()
114+
else:
115+
raise SystemExit(f"Login failed after 2 attempts: {err}")
131116

132117
def _logout_and_login(self):
133118
"""Handle logout and then login when app starts authenticated"""

sample/Tests/test/test_windows_helpers.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,25 +538,45 @@ def login():
538538
time.sleep(3)
539539

540540
try:
541-
# Check what's actually on the page
542541
buttons = driver.find_elements(By.TAG_NAME, "button")
543542
print(f"Found {len(buttons)} buttons on page:")
544-
for i, btn in enumerate(buttons[:5]): # Show first 5 buttons
543+
for i, btn in enumerate(buttons[:10]):
545544
try:
546545
text = btn.text.strip()
547546
if text:
548547
print(f" Button {i}: '{text}'")
549548
except:
550549
pass
551-
552-
# Wait for the deep link dialog to appear and click the button
553-
# Use more specific selector to avoid clicking "Restore" button
550+
554551
product_name = os.getenv("UNITY_APP_NAME", get_product_name())
555-
deep_link_button = wait.until(EC.element_to_be_clickable((By.XPATH, f"//button[text()='Open {product_name}.cmd']")))
556-
deep_link_button.click()
557-
print("Clicked deep link permission dialog - Unity should receive redirect")
552+
deep_link_selectors = [
553+
f"//button[contains(text(),'Open {product_name}')]",
554+
"//button[contains(text(),'Open')]",
555+
"//button[contains(text(),'Allow')]",
556+
"//a[contains(text(),'Open')]",
557+
]
558+
559+
clicked = False
560+
for selector in deep_link_selectors:
561+
try:
562+
deep_link_button = WebDriverWait(driver, 5).until(
563+
EC.element_to_be_clickable((By.XPATH, selector)))
564+
btn_text = deep_link_button.text.strip()
565+
deep_link_button.click()
566+
print(f"Clicked deep link button '{btn_text}' with selector: {selector}")
567+
clicked = True
568+
break
569+
except:
570+
continue
571+
572+
if not clicked:
573+
print("No deep link button found with any selector - checking if redirect happened automatically")
574+
current_url = driver.current_url
575+
print(f"Current URL: {current_url}")
576+
if 'checking' in current_url or 'callback' in current_url:
577+
print("Still on checking page - deep link may not have fired")
558578
except Exception as e:
559-
print(f"Deep link dialog not found or failed to click: {e}")
579+
print(f"Deep link dialog handling error: {e}")
560580
print("This may cause the test to timeout waiting for scene change")
561581

562582
# Keep browser alive for Unity deep link redirect

0 commit comments

Comments
 (0)