From 0d422859fad563487959d2949bc11e056b27476d Mon Sep 17 00:00:00 2001 From: hikaps Date: Mon, 6 Jul 2026 14:28:30 -0700 Subject: [PATCH] test(e2e): stop session between session-lifecycle tests sessionRunner is a global manager that persists across tests; a test that starts a session but never stops it (test_two_instances_launch) left the Start/Stop toolbar action on 'Stop Session', so the next test's wait for 'Start Session' timed out. test_streaming_session_calls_helper failed in-suite despite passing in isolation. Add stop_session_if_running() (navigate to SessionSetup, click Stop if present) called from a class-scoped autouse fixture in TestSessionLifecycle. Scoped to session tests so the other ~43 tests pay no per-test navigation overhead (applying it globally pushed the suite past the 30-min ceiling). Verified: full e2e suite now 52 tests, 0 failures (was 1 failed). --- appiumtests/conftest.py | 25 +++++++++++++++++++++++++ appiumtests/test_session.py | 11 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/appiumtests/conftest.py b/appiumtests/conftest.py index 08cd61f..b783fd3 100644 --- a/appiumtests/conftest.py +++ b/appiumtests/conftest.py @@ -169,6 +169,31 @@ def go_home(driver): wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Welcome to CouchPlay"))) +def stop_session_if_running(driver, timeout=2): + """Ensure no session is left running between session tests. + + sessionRunner is a global manager that persists across pages, so a test + that starts a session but never stops it leaves the Start/Stop toolbar + action reading "Stop Session" -- and the next test waiting for "Start + Session" times out (observed: test_streaming_session_calls_helper fails + after test_two_instances_launch). Navigates to SessionSetup (where the + action lives) and stops if running; a no-op when nothing is. Scoped to + session tests via an autouse fixture in TestSessionLifecycle so the other + ~43 tests pay no per-test navigation overhead. + """ + from selenium.common.exceptions import TimeoutException + + try: + go_home(driver) + click_by_object_name(driver, "cardNewSession", timeout) + wait_for_element(driver, AppiumBy.ACCESSIBILITY_ID, "spinPlayerCount", timeout) + stop_btn = wait_for_element_clickable(driver, AppiumBy.NAME, "Stop Session", timeout) + stop_btn.click() + wait_for_element(driver, AppiumBy.NAME, "Start Session", timeout=5) + except TimeoutException: + pass + + def wait_for_element(driver, by, value, timeout=DEFAULT_TIMEOUT): return WebDriverWait(driver, timeout).until( EC.presence_of_element_located((by, value)) diff --git a/appiumtests/test_session.py b/appiumtests/test_session.py index 6ffef00..c09a38d 100644 --- a/appiumtests/test_session.py +++ b/appiumtests/test_session.py @@ -4,6 +4,7 @@ import pytest from appium.webdriver.common.appiumby import AppiumBy from helpers.base_test import BaseTest +from conftest import stop_session_if_running import json import os @@ -19,6 +20,16 @@ class TestSessionLifecycle(BaseTest): + @pytest.fixture(autouse=True) + def _stop_session_after(self, driver): + # sessionRunner is global and persists across tests. Without stopping + # a session here, a test that starts one (e.g. test_two_instances_launch) + # leaves the toolbar action on "Stop Session", so the next test's wait + # for "Start Session" times out. Scoped to this class so the other ~43 + # tests pay no overhead. + yield + stop_session_if_running(driver) + def test_session_setup_with_helper(self, driver, mock_helper, test_users): self.navigate_to_session_setup(driver) title = self.wait_for_element(