Skip to content

Commit

Permalink
Add "--final-debug" option for a breakpoint after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmintz committed Jun 26, 2022
1 parent 7d55b24 commit f4ad125
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ The code above will leave your browser window open in case there's a failure. (i
--enable-sync # (Enable "Chrome Sync".)
--use-auto-ext # (Use Chrome's automation extension.)
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
--dash-title=STRING # (Set the title shown for the generated dashboard.)
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)
Expand Down
1 change: 1 addition & 0 deletions examples/raw_parameter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
sb._multithreaded = False
sb._reuse_session = False
sb._crumbs = False
sb._final_debug = False
sb.visual_baseline = False
sb.window_size = None
sb.maximize_option = False
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 @@ -157,6 +157,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--enable-sync # (Enable "Chrome Sync".)
--use-auto-ext # (Use Chrome's automation extension.)
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
--dash-title=STRING # (Set the title shown for the generated dashboard.)
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)
Expand Down
13 changes: 13 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __initialize_variables(self):
self._html_report_extra = [] # (Used by pytest_plugin.py)
self._last_page_screenshot = None
self._last_page_url = None
self._final_debug = None
self._default_driver = None
self._drivers_list = []
self._drivers_browser_map = {}
Expand Down Expand Up @@ -12117,6 +12118,7 @@ def setUp(self, masterqa_mode=False):
self.extension_zip = sb_config.extension_zip
self.extension_dir = sb_config.extension_dir
self.external_pdf = sb_config.external_pdf
self._final_debug = sb_config.final_debug
self.window_size = sb_config.window_size
window_size = self.window_size
if window_size:
Expand Down Expand Up @@ -13078,6 +13080,13 @@ def __activate_behave_post_mortem_debug_mode(self):
ipdb.post_mortem(sb_config.behave_step.exc_traceback)
# Post Mortem Debug Mode ("behave -D pdb")

def __activate_debug_mode_in_teardown(self):
"""Activate Debug Mode in tearDown() when using "--final-debug"."""
import ipdb

ipdb.set_trace()
# Final Debug Mode ("--final-debug")

def has_exception(self):
"""(This method should ONLY be used in custom tearDown() methods.)
This method returns True if the test failed or raised an exception.
Expand Down Expand Up @@ -13274,6 +13283,8 @@ def tearDown(self):
self.__process_dashboard(has_exception)
else:
self.__process_dashboard(has_exception)
if self._final_debug:
self.__activate_debug_mode_in_teardown()
# (Pytest) Finally close all open browser windows
self.__quit_all_drivers()
if self.headless or self.xvfb:
Expand Down Expand Up @@ -13420,6 +13431,8 @@ def tearDown(self):
if hasattr(self, "is_behave") and self.is_behave and has_exception:
if hasattr(sb_config, "pdb_option") and sb_config.pdb_option:
self.__activate_behave_post_mortem_debug_mode()
if self._final_debug:
self.__activate_debug_mode_in_teardown()
# (Nosetests / Behave / Pure Python) Close all open browser windows
self.__quit_all_drivers()
# Resume tearDown() for all test runners, (Pytest / Nosetests / Behave)
Expand Down
12 changes: 12 additions & 0 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def pytest_addoption(parser):
--enable-sync (Enable "Chrome Sync".)
--use-auto-ext (Use Chrome's automation extension.)
--remote-debug (Enable Chrome's Remote Debugger on http://localhost:9222)
--final-debug (Enter Debug Mode after each test ends. Don't use with CI!)
--dashboard (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
--dash-title=STRING (Set the title shown for the generated dashboard.)
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
Expand Down Expand Up @@ -832,6 +833,16 @@ def pytest_addoption(parser):
http://localhost:9222 while Chromedriver is running.
Info: chromedevtools.github.io/devtools-protocol/""",
)
parser.addoption(
"--final-debug",
action="store_true",
dest="final_debug",
default=False,
help="""Enter Debug Mode at the end of each test.
To enter Debug Mode only on failures, use "--pdb".
If using both "--final-debug" and "--pdb" together,
then Debug Mode will activate twice on failures.""",
)
parser.addoption(
"--dashboard",
action="store_true",
Expand Down Expand Up @@ -1209,6 +1220,7 @@ def pytest_configure(config):
sb_config.no_sandbox = config.getoption("no_sandbox")
sb_config.disable_gpu = config.getoption("disable_gpu")
sb_config.remote_debug = config.getoption("remote_debug")
sb_config.final_debug = config.getoption("final_debug")
sb_config.dashboard = config.getoption("dashboard")
sb_config.dash_title = config.getoption("dash_title")
sb_config.swiftshader = config.getoption("swiftshader")
Expand Down
12 changes: 12 additions & 0 deletions seleniumbase/plugins/selenium_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SeleniumBrowser(Plugin):
--enable-sync (Enable "Chrome Sync".)
--use-auto-ext (Use Chrome's automation extension.)
--remote-debug (Enable Chrome's Remote Debugger on http://localhost:9222)
--final-debug (Enter Debug Mode after each test ends. Don't use with CI!)
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
--incognito (Enable Chrome's Incognito mode.)
--guest (Enable Chrome's Guest mode.)
Expand Down Expand Up @@ -571,6 +572,16 @@ def options(self, parser, env):
http://localhost:9222 while Chromedriver is running.
Info: chromedevtools.github.io/devtools-protocol/""",
)
parser.add_option(
"--final-debug",
action="store_true",
dest="final_debug",
default=False,
help="""Enter Debug Mode at the end of each test.
To enter Debug Mode only on failures, use "--pdb".
If using both "--final-debug" and "--pdb" together,
then Debug Mode will activate twice on failures.""",
)
parser.add_option(
"--swiftshader",
action="store_true",
Expand Down Expand Up @@ -769,6 +780,7 @@ def beforeTest(self, test):
test.test.no_sandbox = self.options.no_sandbox
test.test.disable_gpu = self.options.disable_gpu
test.test.remote_debug = self.options.remote_debug
test.test._final_debug = self.options.final_debug
test.test.swiftshader = self.options.swiftshader
test.test.incognito = self.options.incognito
test.test.guest_mode = self.options.guest_mode
Expand Down

0 comments on commit f4ad125

Please sign in to comment.