-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_run_tests.py
57 lines (45 loc) · 1.52 KB
/
_run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import time
import sys
import logging
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger()
# Chrome options
options = Options()
options.headless = False # Set to True for headless mode
service = Service()
# Set up Chrome driver
driver = webdriver.Chrome(service=service, options=options)
# Set script timeout
driver.set_script_timeout(3600)
# Function to retrieve browser console logs
def log_browser_console():
logs = driver.get_log('browser')
for entry in logs:
logger.log(getattr(logging, entry['level'].upper(), logging.INFO), entry['message'])
# Start by opening the page
driver.get('http://localhost:1122/')
try:
finished_loading = False
for _ in range(3600):
finished_loading = driver.execute_script('return window.finished_loading === true')
if finished_loading:
break
log_browser_console() # Check for console logs
time.sleep(1)
if not finished_loading:
raise Exception("Timeout waiting for page to load.")
result = driver.execute_script('return run_tests();')
print('exit-code:', result)
# Log any remaining console messages
log_browser_console()
sys.exit(result)
except Exception as e:
print('Error:', str(e))
sys.exit(255)
finally:
driver.quit()