Skip to content

Commit c85ff09

Browse files
authored
Merge pull request #1377 from seleniumbase/reliability-recorder-and-debug-options
Updates for: The Recorder, Reliability, and Debug Options
2 parents 240c961 + 5cfd1e6 commit c85ff09

File tree

11 files changed

+84
-8
lines changed

11 files changed

+84
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ The code above will leave your browser window open in case there's a failure. (i
410410
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
411411
-s # See print statements. (Should be on by default with pytest.ini present.)
412412
--junit-xml=report.xml # Creates a junit-xml report after tests finish.
413-
--pdb # If a test fails, pause run and enter debug mode. (Don't use with CI!)
413+
--pdb # If a test fails, enter Post Mortem Debug Mode. (Don't use with CI!)
414+
--trace # Enter Debug Mode at the beginning of each test. (Don't use with CI!)
414415
-m=MARKER # Run tests with the specified pytest marker.
415416
```
416417
@@ -477,6 +478,7 @@ The code above will leave your browser window open in case there's a failure. (i
477478
--enable-sync # (Enable "Chrome Sync".)
478479
--use-auto-ext # (Use Chrome's automation extension.)
479480
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
481+
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
480482
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
481483
--dash-title=STRING # (Set the title shown for the generated dashboard.)
482484
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
sb._multithreaded = False
6969
sb._reuse_session = False
7070
sb._crumbs = False
71+
sb._final_debug = False
7172
sb.visual_baseline = False
7273
sb.window_size = None
7374
sb.maximize_option = False

help_docs/customizing_test_runs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ pytest my_first_test.py --settings-file=custom_settings.py
9090
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
9191
-s # See print statements. (Should be on by default with pytest.ini present.)
9292
--junit-xml=report.xml # Creates a junit-xml report after tests finish.
93-
--pdb # If a test fails, pause run and enter debug mode. (Don't use with CI!)
93+
--pdb # If a test fails, enter Post Mortem Debug Mode. (Don't use with CI!)
94+
--trace # Enter Debug Mode at the beginning of each test. (Don't use with CI!)
9495
-m=MARKER # Run tests with the specified pytest marker.
9596
```
9697

@@ -157,6 +158,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
157158
--enable-sync # (Enable "Chrome Sync".)
158159
--use-auto-ext # (Use Chrome's automation extension.)
159160
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
161+
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
160162
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
161163
--dash-title=STRING # (Set the title shown for the generated dashboard.)
162164
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ zipp==3.8.0
1818
ghp-import==2.1.0
1919
readme-renderer==35.0
2020
pymdown-extensions==9.5
21-
importlib-metadata==4.11.4
21+
importlib-metadata==4.12.0
2222
bleach==5.0.0
2323
jsmin==3.0.1
2424
lunr==0.6.2

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "3.3.1"
2+
__version__ = "3.3.2"

seleniumbase/extensions/recorder.zip

0 Bytes
Binary file not shown.

seleniumbase/fixtures/base_case.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def __initialize_variables(self):
138138
self._html_report_extra = [] # (Used by pytest_plugin.py)
139139
self._last_page_screenshot = None
140140
self._last_page_url = None
141+
self._final_debug = None
141142
self._default_driver = None
142143
self._drivers_list = []
143144
self._drivers_browser_map = {}
@@ -356,7 +357,7 @@ def click(
356357
self.__js_click(selector, by=by)
357358
else:
358359
element.click()
359-
except (WebDriverException, MoveTargetOutOfBoundsException):
360+
except MoveTargetOutOfBoundsException:
360361
self.wait_for_ready_state_complete()
361362
try:
362363
self.__js_click(selector, by=by)
@@ -373,6 +374,26 @@ def click(
373374
original_selector=original_selector,
374375
)
375376
element.click()
377+
except WebDriverException as e:
378+
if "cannot determine loading status" in e.msg:
379+
pass # Odd issue where the click did happen. Continue.
380+
else:
381+
self.wait_for_ready_state_complete()
382+
try:
383+
self.__js_click(selector, by=by)
384+
except Exception:
385+
try:
386+
self.__jquery_click(selector, by=by)
387+
except Exception:
388+
# One more attempt to click on the element
389+
element = page_actions.wait_for_element_visible(
390+
self.driver,
391+
selector,
392+
by,
393+
timeout=timeout,
394+
original_selector=original_selector,
395+
)
396+
element.click()
376397
latest_window_count = len(self.driver.window_handles)
377398
if (
378399
latest_window_count > pre_window_count
@@ -572,7 +593,13 @@ def update_text(
572593
self.wait_for_ready_state_complete()
573594
else:
574595
element.send_keys(text[:-1])
575-
element.send_keys(Keys.RETURN)
596+
try:
597+
element.send_keys(Keys.RETURN)
598+
except WebDriverException as e:
599+
if "cannot determine loading status" in e.msg:
600+
pass # Odd issue where the click did happen. Continue.
601+
else:
602+
raise e
576603
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
577604
self.wait_for_ready_state_complete()
578605
except (StaleElementReferenceException, ENI_Exception):
@@ -586,7 +613,13 @@ def update_text(
586613
element.send_keys(text)
587614
else:
588615
element.send_keys(text[:-1])
589-
element.send_keys(Keys.RETURN)
616+
try:
617+
element.send_keys(Keys.RETURN)
618+
except WebDriverException as e:
619+
if "cannot determine loading status" in e.msg:
620+
pass # Odd issue where the click did happen. Continue.
621+
else:
622+
raise e
590623
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
591624
self.wait_for_ready_state_complete()
592625
if (
@@ -12085,6 +12118,7 @@ def setUp(self, masterqa_mode=False):
1208512118
self.extension_zip = sb_config.extension_zip
1208612119
self.extension_dir = sb_config.extension_dir
1208712120
self.external_pdf = sb_config.external_pdf
12121+
self._final_debug = sb_config.final_debug
1208812122
self.window_size = sb_config.window_size
1208912123
window_size = self.window_size
1209012124
if window_size:
@@ -13046,6 +13080,13 @@ def __activate_behave_post_mortem_debug_mode(self):
1304613080
ipdb.post_mortem(sb_config.behave_step.exc_traceback)
1304713081
# Post Mortem Debug Mode ("behave -D pdb")
1304813082

13083+
def __activate_debug_mode_in_teardown(self):
13084+
"""Activate Debug Mode in tearDown() when using "--final-debug"."""
13085+
import ipdb
13086+
13087+
ipdb.set_trace()
13088+
# Final Debug Mode ("--final-debug")
13089+
1304913090
def has_exception(self):
1305013091
"""(This method should ONLY be used in custom tearDown() methods.)
1305113092
This method returns True if the test failed or raised an exception.
@@ -13242,6 +13283,8 @@ def tearDown(self):
1324213283
self.__process_dashboard(has_exception)
1324313284
else:
1324413285
self.__process_dashboard(has_exception)
13286+
if self._final_debug:
13287+
self.__activate_debug_mode_in_teardown()
1324513288
# (Pytest) Finally close all open browser windows
1324613289
self.__quit_all_drivers()
1324713290
if self.headless or self.xvfb:
@@ -13388,6 +13431,8 @@ def tearDown(self):
1338813431
if hasattr(self, "is_behave") and self.is_behave and has_exception:
1338913432
if hasattr(sb_config, "pdb_option") and sb_config.pdb_option:
1339013433
self.__activate_behave_post_mortem_debug_mode()
13434+
if self._final_debug:
13435+
self.__activate_debug_mode_in_teardown()
1339113436
# (Nosetests / Behave / Pure Python) Close all open browser windows
1339213437
self.__quit_all_drivers()
1339313438
# Resume tearDown() for all test runners, (Pytest / Nosetests / Behave)

seleniumbase/js_code/recorder_js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@
159159
non_id_attributes.push('href');
160160
non_id_attributes.push('label');
161161
non_id_attributes.push('class');
162-
non_id_attributes.push('value');
163162
non_id_attributes.push('for');
164163
non_id_attributes.push('placeholder');
164+
non_id_attributes.push('value');
165165
non_id_attributes.push('ng-if');
166166
non_id_attributes.push('src');
167167
selector_by_attr = [];

seleniumbase/plugins/pytest_plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def pytest_addoption(parser):
7979
--enable-sync (Enable "Chrome Sync".)
8080
--use-auto-ext (Use Chrome's automation extension.)
8181
--remote-debug (Enable Chrome's Remote Debugger on http://localhost:9222)
82+
--final-debug (Enter Debug Mode after each test ends. Don't use with CI!)
8283
--dashboard (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
8384
--dash-title=STRING (Set the title shown for the generated dashboard.)
8485
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
@@ -832,6 +833,16 @@ def pytest_addoption(parser):
832833
http://localhost:9222 while Chromedriver is running.
833834
Info: chromedevtools.github.io/devtools-protocol/""",
834835
)
836+
parser.addoption(
837+
"--final-debug",
838+
action="store_true",
839+
dest="final_debug",
840+
default=False,
841+
help="""Enter Debug Mode at the end of each test.
842+
To enter Debug Mode only on failures, use "--pdb".
843+
If using both "--final-debug" and "--pdb" together,
844+
then Debug Mode will activate twice on failures.""",
845+
)
835846
parser.addoption(
836847
"--dashboard",
837848
action="store_true",
@@ -1209,6 +1220,7 @@ def pytest_configure(config):
12091220
sb_config.no_sandbox = config.getoption("no_sandbox")
12101221
sb_config.disable_gpu = config.getoption("disable_gpu")
12111222
sb_config.remote_debug = config.getoption("remote_debug")
1223+
sb_config.final_debug = config.getoption("final_debug")
12121224
sb_config.dashboard = config.getoption("dashboard")
12131225
sb_config.dash_title = config.getoption("dash_title")
12141226
sb_config.swiftshader = config.getoption("swiftshader")

seleniumbase/plugins/selenium_plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SeleniumBrowser(Plugin):
6060
--enable-sync (Enable "Chrome Sync".)
6161
--use-auto-ext (Use Chrome's automation extension.)
6262
--remote-debug (Enable Chrome's Remote Debugger on http://localhost:9222)
63+
--final-debug (Enter Debug Mode after each test ends. Don't use with CI!)
6364
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
6465
--incognito (Enable Chrome's Incognito mode.)
6566
--guest (Enable Chrome's Guest mode.)
@@ -571,6 +572,16 @@ def options(self, parser, env):
571572
http://localhost:9222 while Chromedriver is running.
572573
Info: chromedevtools.github.io/devtools-protocol/""",
573574
)
575+
parser.add_option(
576+
"--final-debug",
577+
action="store_true",
578+
dest="final_debug",
579+
default=False,
580+
help="""Enter Debug Mode at the end of each test.
581+
To enter Debug Mode only on failures, use "--pdb".
582+
If using both "--final-debug" and "--pdb" together,
583+
then Debug Mode will activate twice on failures.""",
584+
)
574585
parser.add_option(
575586
"--swiftshader",
576587
action="store_true",
@@ -769,6 +780,7 @@ def beforeTest(self, test):
769780
test.test.no_sandbox = self.options.no_sandbox
770781
test.test.disable_gpu = self.options.disable_gpu
771782
test.test.remote_debug = self.options.remote_debug
783+
test.test._final_debug = self.options.final_debug
772784
test.test.swiftshader = self.options.swiftshader
773785
test.test.incognito = self.options.incognito
774786
test.test.guest_mode = self.options.guest_mode

0 commit comments

Comments
 (0)