11"""This module is a fixtures for the ui testing."""
22
3- # cspell: ignore capmanager capturemanager pluginmanager getplugin
3+ # cspell: ignore capmanager capturemanager pluginmanager getplugin healthcheck
44# pylint: disable=E0401
55import contextlib
66import logging
1616from selenium .common import WebDriverException
1717from selenium .webdriver .remote .webdriver import WebDriver
1818
19+ from test .selenium .const import CONTAINER_NAME
20+
1921if TYPE_CHECKING :
2022 from _pytest .capture import CaptureManager
2123 from selenium .webdriver .common .options import ArgOptions
3133)
3234
3335# Initialize logging
34- log = logging .getLogger (__name__ )
36+ log = logging .getLogger (__package__ )
37+
38+
39+ def is_container_healthy () -> bool :
40+ """Check if the selenium container is healthy."""
41+ result = subprocess .run (
42+ f"podman healthcheck run { CONTAINER_NAME } " ,
43+ shell = True ,
44+ check = False ,
45+ text = True ,
46+ capture_output = True ,
47+ )
48+ return result .returncode == 0
3549
3650
3751@pytest .fixture (scope = "session" )
@@ -46,15 +60,33 @@ def browser_setup(
4660 capmanager : CaptureManager = request .config .pluginmanager .getplugin (
4761 "capturemanager"
4862 ) # type: ignore[name-defined]
49- log .info (
50- "Starting selenium server at http://localhost:4444 and vnc://localhost:5999"
51- )
52- with capmanager .global_and_fixture_disabled ():
63+ if not is_container_healthy ():
5364 subprocess .run (
54- "podman-compose up --remove-orphans --timeout 5 -d selenium-vscode" ,
55- check = True ,
65+ f"podman stop { CONTAINER_NAME } 2>/dev/null || true" ,
5666 shell = True ,
67+ check = False ,
68+ text = True ,
69+ capture_output = True ,
70+ )
71+ log .info (
72+ "Starting selenium server at http://localhost:4444 and vnc://localhost:5999"
5773 )
74+ with capmanager .global_and_fixture_disabled ():
75+ subprocess .run (
76+ f"podman-compose up --quiet-pull --remove-orphans --timeout 5 -d { CONTAINER_NAME } " ,
77+ check = True ,
78+ shell = True ,
79+ )
80+ count = 0
81+ while True :
82+ if is_container_healthy ():
83+ break
84+ count += 1
85+ time .sleep (1 )
86+ log .info (
87+ "Waiting for container %s to be healthy: %s" , CONTAINER_NAME , count
88+ )
89+
5890 browser = os .environ .get ("BROWSER_TYPE" )
5991 options : ArgOptions # type: ignore[name-defined]
6092 if browser == "chrome" :
0 commit comments