Skip to content

Commit 6df9a9d

Browse files
test(ui): stabilize macOS login and upload Player.log
1 parent 45db4c3 commit 6df9a9d

2 files changed

Lines changed: 77 additions & 3 deletions

File tree

.github/workflows/ui-tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,43 @@ jobs:
156156
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
157157
working-directory: sample-unity6/Tests
158158
run: pytest -xs test/test_mac.py::MacTest
159+
- name: Collect Unity Player logs (macOS)
160+
if: always()
161+
run: |
162+
set -euo pipefail
163+
workspaceLogs="${{ github.workspace }}/sample-unity6/player-logs"
164+
zipPath="${{ github.workspace }}/sample-unity6/Unity6-macOS-PlayerLogs.zip"
165+
mkdir -p "$workspaceLogs"
166+
167+
# Unity Player.log location on macOS
168+
unityLogsDir="$HOME/Library/Logs/Unity"
169+
if [ -d "$unityLogsDir" ]; then
170+
cp -R "$unityLogsDir" "$workspaceLogs/UnityLogs" || true
171+
echo "Copied Unity logs from: $unityLogsDir"
172+
else
173+
echo "Unity logs directory not found: $unityLogsDir"
174+
fi
175+
176+
# Try to collect crash reports (if any)
177+
diagDir="$HOME/Library/Logs/DiagnosticReports"
178+
if [ -d "$diagDir" ]; then
179+
mkdir -p "$workspaceLogs/DiagnosticReports"
180+
cp -R "$diagDir/"*Sample*Unity*6*macOS* "$workspaceLogs/DiagnosticReports/" 2>/dev/null || true
181+
cp -R "$diagDir/"*Unity* "$workspaceLogs/DiagnosticReports/" 2>/dev/null || true
182+
echo "Attempted to copy DiagnosticReports from: $diagDir"
183+
else
184+
echo "DiagnosticReports directory not found: $diagDir"
185+
fi
186+
187+
rm -f "$zipPath" || true
188+
(cd "${{ github.workspace }}/sample-unity6" && zip -r "Unity6-macOS-PlayerLogs.zip" "player-logs" >/dev/null) || true
189+
echo "Player logs zip created: $zipPath"
190+
- name: Upload Unity Player logs (macOS)
191+
if: always()
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: Unity6-macOS-Player-Logs
195+
path: sample-unity6/Unity6-macOS-PlayerLogs.zip
159196
- name: Remove temporary keychain
160197
if: always()
161198
run: |

sample/Tests/test/test_mac.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_1_login(self):
186186
for attempt in range(2):
187187
try:
188188
# Check app state
189-
login_button = self.altdriver.find_object(By.NAME, "LoginBtn")
189+
login_button = self.altdriver.wait_for_object(By.NAME, "LoginBtn")
190190
print("Found login button, app is in the correct state")
191191

192192
# Login
@@ -208,7 +208,44 @@ def test_1_login(self):
208208

209209
# Relogin
210210
print("Try reset the app and log out once...")
211-
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
211+
bring_sample_app_to_foreground()
212+
213+
# Determine which scene we're in before trying to use ReloginBtn.
214+
# CI can occasionally be out-of-sync (still unauthenticated / mid-transition).
215+
scene_deadline = time.time() + 30
216+
current_scene = ""
217+
while time.time() < scene_deadline:
218+
try:
219+
current_scene = self.altdriver.get_current_scene()
220+
if current_scene in ("AuthenticatedScene", "UnauthenticatedScene"):
221+
break
222+
except Exception:
223+
pass
224+
time.sleep(1)
225+
print(f"Current scene before reset attempt: {current_scene}")
226+
227+
if current_scene != "AuthenticatedScene":
228+
# If we're not authenticated, there's nothing to "reset" via Relogin+Logout.
229+
# Ensure browser is closed and just retry the normal login flow.
230+
self.stop_browser()
231+
print("Not in AuthenticatedScene; skipping ReloginBtn reset and retrying login...")
232+
time.sleep(5)
233+
continue
234+
235+
# Some runs fail because we try to locate ReloginBtn while not on the right scene.
236+
# Wait for AuthenticatedScene explicitly, then try ReloginBtn, with fallback diagnostics.
237+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene", timeout=60)
238+
try:
239+
self.altdriver.wait_for_object(By.NAME, "ReloginBtn", timeout=60).tap()
240+
except Exception as relogin_err:
241+
# Fallback: if ReloginBtn is unexpectedly missing, print the scene and try LoginBtn.
242+
try:
243+
print(f"ReloginBtn not found on scene={self.altdriver.get_current_scene()}: {relogin_err}")
244+
except Exception:
245+
print(f"ReloginBtn not found and could not read current scene: {relogin_err}")
246+
# This keeps the test resilient if the UI changed but still provides a login entrypoint.
247+
self.stop_browser()
248+
raise
212249

213250
# Wait for authenticated screen
214251
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
@@ -231,4 +268,4 @@ def test_3_passport_functions(self):
231268
self.test_1_passport_functions()
232269

233270
def test_5_zkevm_functions(self):
234-
self.test_3_zkevm_functions()
271+
self.test_3_zkevm_functions()

0 commit comments

Comments
 (0)