Skip to content

Commit

Permalink
Merge pull request #1419 from seleniumbase/debugging-options-and-reli…
Browse files Browse the repository at this point in the history
…ability

Add a debugging option and improve reliability
  • Loading branch information
mdmintz committed Jul 15, 2022
2 parents e88e06d + 7e5f10f commit eda73c6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ The code above will leave your browser window open in case there's a failure. (i
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.)
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
--list-fail-page # (After each failing test, list the URL of the failure.)
```
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
Expand Down
1 change: 1 addition & 0 deletions help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.)
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
--list-fail-page # (After each failing test, list the URL of the failure.)
```

(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "3.5.4"
__version__ = "3.5.5"
1 change: 1 addition & 0 deletions seleniumbase/core/log_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
last_page = url
else:
last_page = get_last_page(driver)
sb_config._fail_page = last_page
timestamp, the_date, the_time = get_master_time()
test_id = get_test_id(test) # pytest runnable display_id (with the "::")
data_to_save = []
Expand Down
14 changes: 13 additions & 1 deletion seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5016,6 +5016,8 @@ def js_click(
element = self.wait_for_element_present(
selector, by=by, timeout=settings.SMALL_TIMEOUT
)
if not page_actions.is_element_clickable(self.driver, selector, by):
self.wait_for_ready_state_complete()
scroll_done = False
if self.is_element_visible(selector, by=by):
scroll_done = True
Expand Down Expand Up @@ -11584,6 +11586,8 @@ def __js_click(self, selector, by="css selector"):
css_selector = self.convert_to_css_selector(selector, by=by)
css_selector = re.escape(css_selector) # Add "\\" to special chars
css_selector = self.__escape_quotes_if_needed(css_selector)
is_visible = self.is_element_visible(selector, by=by)
current_url = self.get_current_url()
script = (
"""var simulateClick = function (elem) {
var evt = new MouseEvent('click', {
Expand All @@ -11600,10 +11604,18 @@ def __js_click(self, selector, by="css selector"):
try:
self.execute_script(script)
except Exception as e:
# If element was visible but no longer, or on a different page now,
# assume that the click actually worked and continue with the test.
if (
(is_visible and not self.is_element_visible(selector, by=by))
or current_url != self.get_current_url()
):
return # The click worked, but threw an Exception. Keep going.
# It appears the first click didn't work. Make another attempt.
self.wait_for_ready_state_complete()
if "Cannot read properties of null" in e.msg:
page_actions.wait_for_element_present(
self.driver, selector, by, timeout=3
self.driver, selector, by, timeout=5
)
if not page_actions.is_element_clickable(
self.driver, selector, by
Expand Down
16 changes: 16 additions & 0 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def pytest_addoption(parser):
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
--external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
--timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
--list-fail-page (After each failing test, list the URL of the failure.)
"""
c1 = ""
c2 = ""
Expand Down Expand Up @@ -1015,6 +1016,17 @@ def pytest_addoption(parser):
by the multiplier when waiting for page elements.
Unused when tests override the default value.""",
)
parser.addoption(
"--list-fail-page",
"--list-fail-pages",
action="store_true",
dest="fail_page",
default=False,
help="""(For debugging) After each failing test, list the URL
where the failure occurred.
Useful when you don't have access to the latest_logs/
folder, such as when running tests in GitHub Actions.""",
)

sys_argv = sys.argv
arg_join = " ".join(sys.argv)
Expand Down Expand Up @@ -1274,8 +1286,10 @@ def pytest_configure(config):
sb_config.visual_baseline = config.getoption("visual_baseline")
sb_config.external_pdf = config.getoption("external_pdf")
sb_config.timeout_multiplier = config.getoption("timeout_multiplier")
sb_config.list_fp = config.getoption("fail_page")
sb_config._is_timeout_changed = False
sb_config._has_logs = False
sb_config._fail_page = None
sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT
sb_config._LARGE_TIMEOUT = settings.LARGE_TIMEOUT
sb_config.pytest_html_report = config.getoption("htmlpath") # --html=FILE
Expand Down Expand Up @@ -1554,6 +1568,8 @@ def pytest_runtest_teardown(item):
pass
except Exception:
pass
if sb_config._has_exception and sb_config.list_fp and sb_config._fail_page:
sys.stderr.write("\n=> Fail Page: %s\n" % sb_config._fail_page)


def pytest_sessionfinish(session):
Expand Down

0 comments on commit eda73c6

Please sign in to comment.