1717SCREENSHOTS_DIR = os .path .join (os .path .dirname (__file__ ), "screenshots" )
1818os .makedirs (SCREENSHOTS_DIR , exist_ok = True )
1919
20+
2021@pytest .fixture
2122def subtests (request ):
2223 """Fixture to enable subtests for step-by-step reporting in HTML"""
@@ -69,6 +70,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
6970
7071 return SubTests (request )
7172
73+
7274@pytest .fixture (scope = "session" )
7375def login_logout ():
7476 """Perform login and browser close once in a session"""
@@ -107,7 +109,6 @@ def pytest_runtest_setup(item):
107109 log_streams [item .nodeid ] = (handler , stream )
108110
109111
110-
111112@pytest .hookimpl (tryfirst = True )
112113def pytest_html_report_title (report ):
113114 """Set custom HTML report title"""
@@ -132,25 +133,25 @@ def pytest_runtest_makereport(item, call):
132133 test_name = item .name .replace (" " , "_" ).replace ("/" , "_" )
133134 screenshot_name = f"screenshot_{ test_name } _{ timestamp } .png"
134135 screenshot_path = os .path .join (SCREENSHOTS_DIR , screenshot_name )
135-
136+
136137 # Take screenshot
137138 page .screenshot (path = screenshot_path )
138-
139+
139140 # Add screenshot link to report
140141 if not hasattr (report , 'extra' ):
141142 report .extra = []
142-
143+
143144 # Add screenshot as a link in the Links column
144145 # Use relative path from report.html location
145146 relative_path = os .path .relpath (
146147 screenshot_path ,
147148 os .path .dirname (os .path .abspath ("report.html" ))
148149 )
149-
150+
150151 # pytest-html expects this format for extras
151152 from pytest_html import extras
152153 report .extra .append (extras .url (relative_path , name = 'Screenshot' ))
153-
154+
154155 logging .info ("Screenshot saved: %s" , screenshot_path )
155156 except Exception as exc : # pylint: disable=broad-exception-caught
156157 logging .error ("Failed to capture screenshot: %s" , str (exc ))
@@ -210,6 +211,7 @@ def pytest_runtest_makereport(item, call):
210211 else :
211212 report .description = ""
212213
214+
213215def pytest_collection_modifyitems (items ):
214216 """Modify test items to use custom node IDs"""
215217 for item in items :
0 commit comments