Skip to content

Commit cb3f454

Browse files
committed
Add pytest option "--list-fail-page" to list URLs of failures
1 parent e88e06d commit cb3f454

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

seleniumbase/core/log_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
131131
last_page = url
132132
else:
133133
last_page = get_last_page(driver)
134+
sb_config._fail_page = last_page
134135
timestamp, the_date, the_time = get_master_time()
135136
test_id = get_test_id(test) # pytest runnable display_id (with the "::")
136137
data_to_save = []

seleniumbase/plugins/pytest_plugin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def pytest_addoption(parser):
9797
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
9898
--external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
9999
--timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
100+
--list-fail-page (After each failing test, list the URL of the failure.)
100101
"""
101102
c1 = ""
102103
c2 = ""
@@ -1015,6 +1016,17 @@ def pytest_addoption(parser):
10151016
by the multiplier when waiting for page elements.
10161017
Unused when tests override the default value.""",
10171018
)
1019+
parser.addoption(
1020+
"--list-fail-page",
1021+
"--list-fail-pages",
1022+
action="store_true",
1023+
dest="fail_page",
1024+
default=False,
1025+
help="""(For debugging) After each failing test, list the URL
1026+
where the failure occurred.
1027+
Useful when you don't have access to the latest_logs/
1028+
folder, such as when running tests in GitHub Actions.""",
1029+
)
10181030

10191031
sys_argv = sys.argv
10201032
arg_join = " ".join(sys.argv)
@@ -1274,8 +1286,10 @@ def pytest_configure(config):
12741286
sb_config.visual_baseline = config.getoption("visual_baseline")
12751287
sb_config.external_pdf = config.getoption("external_pdf")
12761288
sb_config.timeout_multiplier = config.getoption("timeout_multiplier")
1289+
sb_config.list_fp = config.getoption("fail_page")
12771290
sb_config._is_timeout_changed = False
12781291
sb_config._has_logs = False
1292+
sb_config._fail_page = None
12791293
sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT
12801294
sb_config._LARGE_TIMEOUT = settings.LARGE_TIMEOUT
12811295
sb_config.pytest_html_report = config.getoption("htmlpath") # --html=FILE
@@ -1554,6 +1568,8 @@ def pytest_runtest_teardown(item):
15541568
pass
15551569
except Exception:
15561570
pass
1571+
if sb_config._has_exception and sb_config.list_fp and sb_config._fail_page:
1572+
sys.stderr.write("\n=> Fail Page: %s\n" % sb_config._fail_page)
15571573

15581574

15591575
def pytest_sessionfinish(session):

0 commit comments

Comments
 (0)