1
+ import datetime
1
2
import logging
2
3
import os
3
4
import platform
4
- import datetime
5
5
from typing import Callable , List , Tuple
6
6
7
7
import pytest
8
8
from selenium import webdriver
9
9
from selenium .common .exceptions import WebDriverException
10
- from selenium .webdriver .firefox .options import Options
11
10
from selenium .webdriver import Firefox
11
+ from selenium .webdriver .firefox .options import Options
12
+
13
+ # pipenv run pytest --fx-executable ./firefox/firefox -n 4 .
12
14
13
15
def screenshot_content (driver : Firefox , opt_ci : bool , test_name : str ) -> None :
14
16
"""
@@ -26,14 +28,19 @@ def screenshot_content(driver: Firefox, opt_ci: bool, test_name: str) -> None:
26
28
driver .save_screenshot (fullpath )
27
29
return
28
30
31
+
29
32
def log_content (opt_ci : bool , driver : Firefox , test_name : str ) -> None :
30
33
"""
31
34
Logs the current browser content, with the appropriate test name and date for reference.
32
35
"""
33
36
artifacts_loc = "artifacts" if opt_ci else ""
34
37
current_time = str (datetime .datetime .now ())
35
- fullpath_chrome = os .path .join (artifacts_loc , f"{ test_name } _{ current_time } _content.html" )
36
- fullpath_content = os .path .join (artifacts_loc , f"{ test_name } _{ current_time } _chrome.html" )
38
+ fullpath_chrome = os .path .join (
39
+ artifacts_loc , f"{ test_name } _{ current_time } _content.html"
40
+ )
41
+ fullpath_content = os .path .join (
42
+ artifacts_loc , f"{ test_name } _{ current_time } _chrome.html"
43
+ )
37
44
38
45
# Save Chrome context page source
39
46
with open (fullpath_chrome , "w" ) as fh :
@@ -47,6 +54,7 @@ def log_content(opt_ci: bool, driver: Firefox, test_name: str) -> None:
47
54
fh .write (output_contents )
48
55
return
49
56
57
+
50
58
def pytest_exception_interact (node , call , report ):
51
59
"""
52
60
Method that wraps all test execution, on any exception/failure an artifact with the information about the failure is kept.
@@ -55,6 +63,7 @@ def pytest_exception_interact(node, call, report):
55
63
try :
56
64
test_name = node .name
57
65
logging .info (f"Handling exception for test: { test_name } " )
66
+ logging .info (node .funcargs )
58
67
driver = node .funcargs ["driver" ]
59
68
opt_ci = node .funcargs ["opt_ci" ]
60
69
if driver :
@@ -184,7 +193,7 @@ def driver(
184
193
set_prefs : List [Tuple ],
185
194
opt_ci : bool ,
186
195
opt_window_size : str ,
187
- env_prep
196
+ env_prep ,
188
197
):
189
198
"""
190
199
Return the webdriver object.
@@ -285,6 +294,7 @@ def log_page_content(driver: webdriver.Firefox, opt_ci: bool):
285
294
"""
286
295
Function that saves the html content into the artifacts on a failed test
287
296
"""
297
+
288
298
def _log_page_content (opt_ci : bool ):
289
299
artifacts_loc = "artifacts" if opt_ci else ""
290
300
fullpath_chrome = os .path .join (artifacts_loc , "page_source_chrome.html" )
@@ -302,4 +312,4 @@ def _log_page_content(opt_ci: bool):
302
312
output_contents = driver .page_source .replace ("><" , ">\n <" )
303
313
fh .write (output_contents )
304
314
305
- return _log_page_content (opt_ci )
315
+ return _log_page_content (opt_ci )
0 commit comments