55
66import pytest
77
8+ from playwright .sync_api import Page
9+
10+ from browsergym .workarena .api .system_properties import get_sys_property
11+ from browsergym .workarena .instance import SNowInstance , fetch_instances
12+ from browsergym .workarena .utils import ui_login
13+
814# bugfix: use same playwright instance in browsergym and pytest
915from utils import setup_playwright
1016
11- from playwright .sync_api import Page
17+ INSTANCE_POOL = fetch_instances ()
18+
19+ if not INSTANCE_POOL :
20+ pytest .skip (
21+ "No ServiceNow instances available from fetch_instances()." , allow_module_level = True
22+ )
1223
13- from browsergym .workarena .instance import SNowInstance
14- from browsergym .workarena .utils import ui_login
1524
25+ @pytest .fixture (
26+ scope = "session" , params = INSTANCE_POOL , ids = [entry ["url" ] for entry in INSTANCE_POOL ]
27+ )
28+ def snow_instance_entry (request ):
29+ return request .param
1630
17- def test_check_is_reachable ():
31+
32+ def test_check_is_reachable (snow_instance_entry ):
1833 """
1934 Test that the ServiceNow instance is reachable
2035
2136 """
22- # This tests that the user's config is correct
23- # If it is not, the creation of the instance object
24- # will simply return an exception
25- instance = SNowInstance ()
37+ # Use the first instance from the pool to avoid random selection in the constructor.
38+ instance = SNowInstance (
39+ snow_url = snow_instance_entry ["url" ],
40+ snow_credentials = ("admin" , snow_instance_entry ["password" ]),
41+ )
2642
2743 # We modify the URL and ensure that the instance is not reachable
2844 instance .snow_url = "https://invalid.url"
@@ -31,22 +47,46 @@ def test_check_is_reachable():
3147 instance ._check_is_reachable ()
3248
3349
34- def test_instance_active (page : Page ):
50+ def test_instance_active (snow_instance_entry , page : Page ):
3551 """
3652 Test that the ServiceNow instance is active (not hibernating)
3753
3854 """
39- instance = SNowInstance ()
55+ instance = SNowInstance (
56+ snow_url = snow_instance_entry ["url" ],
57+ snow_credentials = ("admin" , snow_instance_entry ["password" ]),
58+ )
4059 page .goto (instance .snow_url )
4160 assert (
4261 "hibernating" not in page .title ().lower ()
43- ), f"Instance is not active. Wake it up by navigating to { instance .snow_url } in a browser."
62+ ), f"Instance { instance . snow_url } is not active. Wake it up by navigating to { instance .snow_url } in a browser."
4463
4564
46- def test_credentials (page : Page ):
65+ def test_credentials (snow_instance_entry , page : Page ):
4766 """
4867 Test that the credentials are correct
4968
5069 """
51- instance = SNowInstance ()
52- ui_login (instance = instance , page = page ) # Raises exception if login fails
70+ instance = SNowInstance (
71+ snow_url = snow_instance_entry ["url" ],
72+ snow_credentials = ("admin" , snow_instance_entry ["password" ]),
73+ )
74+ try :
75+ ui_login (instance = instance , page = page ) # Raises exception if login fails
76+ except Exception as exc : # pragma: no cover - adds context for debugging
77+ pytest .fail (f"Login failed on instance { instance .snow_url } : { exc } " )
78+
79+
80+ def test_workarena_installed (snow_instance_entry ):
81+ """
82+ Test that WorkArena installation is detected via the installation date property.
83+
84+ """
85+ instance = SNowInstance (
86+ snow_url = snow_instance_entry ["url" ],
87+ snow_credentials = ("admin" , snow_instance_entry ["password" ]),
88+ )
89+ installation_date = get_sys_property (
90+ instance = instance , property_name = "workarena.installation.date"
91+ )
92+ assert installation_date , f"Instance { instance .snow_url } missing workarena.installation.date."
0 commit comments