Skip to content

Commit f4ad125

Browse files
committed
Add "--final-debug" option for a breakpoint after each test
1 parent 7d55b24 commit f4ad125

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ The code above will leave your browser window open in case there's a failure. (i
477477
--enable-sync # (Enable "Chrome Sync".)
478478
--use-auto-ext # (Use Chrome's automation extension.)
479479
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
480+
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
480481
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
481482
--dash-title=STRING # (Set the title shown for the generated dashboard.)
482483
--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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
157157
--enable-sync # (Enable "Chrome Sync".)
158158
--use-auto-ext # (Use Chrome's automation extension.)
159159
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
160+
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
160161
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
161162
--dash-title=STRING # (Set the title shown for the generated dashboard.)
162163
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)

seleniumbase/fixtures/base_case.py

Lines changed: 13 additions & 0 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 = {}
@@ -12117,6 +12118,7 @@ def setUp(self, masterqa_mode=False):
1211712118
self.extension_zip = sb_config.extension_zip
1211812119
self.extension_dir = sb_config.extension_dir
1211912120
self.external_pdf = sb_config.external_pdf
12121+
self._final_debug = sb_config.final_debug
1212012122
self.window_size = sb_config.window_size
1212112123
window_size = self.window_size
1212212124
if window_size:
@@ -13078,6 +13080,13 @@ def __activate_behave_post_mortem_debug_mode(self):
1307813080
ipdb.post_mortem(sb_config.behave_step.exc_traceback)
1307913081
# Post Mortem Debug Mode ("behave -D pdb")
1308013082

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+
1308113090
def has_exception(self):
1308213091
"""(This method should ONLY be used in custom tearDown() methods.)
1308313092
This method returns True if the test failed or raised an exception.
@@ -13274,6 +13283,8 @@ def tearDown(self):
1327413283
self.__process_dashboard(has_exception)
1327513284
else:
1327613285
self.__process_dashboard(has_exception)
13286+
if self._final_debug:
13287+
self.__activate_debug_mode_in_teardown()
1327713288
# (Pytest) Finally close all open browser windows
1327813289
self.__quit_all_drivers()
1327913290
if self.headless or self.xvfb:
@@ -13420,6 +13431,8 @@ def tearDown(self):
1342013431
if hasattr(self, "is_behave") and self.is_behave and has_exception:
1342113432
if hasattr(sb_config, "pdb_option") and sb_config.pdb_option:
1342213433
self.__activate_behave_post_mortem_debug_mode()
13434+
if self._final_debug:
13435+
self.__activate_debug_mode_in_teardown()
1342313436
# (Nosetests / Behave / Pure Python) Close all open browser windows
1342413437
self.__quit_all_drivers()
1342513438
# Resume tearDown() for all test runners, (Pytest / Nosetests / Behave)

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)