Skip to content

Commit fdd90a5

Browse files
committed
ftx(tests): handle process isolated logout
1 parent 61f4866 commit fdd90a5

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

sample/Tests/test/test_windows.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from alttester import *
44

55
from test import TestConfig, UnityTest
6-
from test_windows_helpers import login, open_sample_app, launch_browser, bring_sample_app_to_foreground, stop_browser, stop_sample_app
6+
from test_windows_helpers import login, open_sample_app, launch_browser, bring_sample_app_to_foreground, stop_browser, stop_sample_app, logout_with_controlled_browser
77

88
class WindowsTest(UnityTest):
99

@@ -179,11 +179,17 @@ def test_7_reconnect_connect_imx(self):
179179
launch_browser()
180180
bring_sample_app_to_foreground()
181181
self.get_altdriver().find_object(By.NAME, "LogoutBtn").tap()
182-
time.sleep(10) # Give more time for logout browser process
182+
183+
# Use controlled browser logout instead of waiting for scene change
184+
logout_with_controlled_browser()
185+
186+
# Give Unity time to process the logout callback
187+
time.sleep(5)
183188
bring_sample_app_to_foreground()
184189

185190
# Wait for authenticated screen
186191
self.get_altdriver().wait_for_current_scene_to_be("UnauthenticatedScene")
192+
187193
stop_browser()
188194
print("Logged out")
189195

@@ -227,6 +233,7 @@ def test_8_connect_imx(self):
227233
bring_sample_app_to_foreground()
228234
print("Logging out...")
229235
self.get_altdriver().find_object(By.NAME, "LogoutBtn").tap()
236+
logout_with_controlled_browser()
230237
time.sleep(5)
231238
bring_sample_app_to_foreground()
232239

sample/Tests/test/test_windows_helpers.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,82 @@ def get_auth_url_from_unity_logs():
8686
print("No auth URL found in Unity logs")
8787
return None
8888

89+
def get_logout_url_from_unity_logs():
90+
"""Monitor Unity logs to capture logout URLs."""
91+
import tempfile
92+
import os
93+
94+
# Unity log file locations on Windows
95+
log_paths = [
96+
os.path.join(os.path.expanduser("~"), "AppData", "LocalLow", "Immutable", "Immutable Sample", "Player.log"),
97+
os.path.join(tempfile.gettempdir(), "UnityPlayer.log"),
98+
"Player.log" # Current directory
99+
]
100+
101+
for log_path in log_paths:
102+
if os.path.exists(log_path):
103+
print(f"Monitoring Unity log for logout URL: {log_path}")
104+
try:
105+
with open(log_path, 'r', encoding='utf-8', errors='ignore') as f:
106+
content = f.read()
107+
# Look for logout URLs in Unity logs
108+
matches = re.findall(r'(?:PASSPORT_LOGOUT_URL: |LaunchAuthURL : )(https?://[^\s]+)', content)
109+
if matches:
110+
# Get the last URL and make sure it's a logout URL
111+
for url in reversed(matches):
112+
if 'logout' in url or 'im-logged-out' in url:
113+
print(f"Found logout URL: {url}")
114+
return url
115+
except Exception as e:
116+
print(f"Error reading log file {log_path}: {e}")
117+
continue
118+
119+
print("No logout URL found in Unity logs")
120+
return None
121+
122+
def logout_with_controlled_browser():
123+
"""Handle logout using the controlled browser instance instead of letting Unity open its own browser."""
124+
print("Starting controlled logout process...")
125+
126+
# Set up Chrome WebDriver options to connect to the existing browser instance
127+
chrome_options = Options()
128+
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
129+
130+
try:
131+
# Connect to the existing browser instance
132+
driver = webdriver.Chrome(options=chrome_options)
133+
print("Connected to existing browser for logout")
134+
135+
# Monitor Unity logs for logout URL
136+
print("Monitoring Unity logs for logout URL...")
137+
logout_url = None
138+
for attempt in range(15): # Try for 15 seconds (shorter timeout)
139+
logout_url = get_logout_url_from_unity_logs()
140+
if logout_url:
141+
break
142+
time.sleep(1)
143+
144+
if logout_url:
145+
print(f"Navigating controlled browser to logout URL: {logout_url}")
146+
driver.get(logout_url)
147+
148+
# Wait for logout to complete (protocol is already configured, no dialogs expected)
149+
time.sleep(3)
150+
print("Logout completed in controlled browser")
151+
152+
# Check final page
153+
current_url = driver.current_url
154+
print(f"Final logout URL: {current_url}")
155+
156+
else:
157+
print("Could not find logout URL in Unity logs - logout may complete without browser interaction")
158+
159+
except Exception as e:
160+
print(f"Error during controlled logout: {e}")
161+
print("Logout may need to be handled by Unity directly")
162+
163+
print("Controlled logout process completed")
164+
89165
def handle_cached_authentication(driver):
90166
"""Handle scenarios where user is already authenticated (cached session)"""
91167
print("Handling cached authentication scenario...")

0 commit comments

Comments
 (0)