Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions appiumtests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions appiumtests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Loading