Skip to content

Commit 8dc34a1

Browse files
authored
Merge pull request #413 from seleniumbase/slow-mode
Add "Slow Mode". Usage: "--slow"
2 parents f7d0d9c + 72bdd6d commit 8dc34a1

File tree

8 files changed

+72
-11
lines changed

8 files changed

+72
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ SeleniumBase provides additional Pytest command-line options for tests:
218218
--start_page=URL # (The starting URL for the web browser when tests begin.)
219219
--log_path=LOG_PATH # (The directory where log files get saved to.)
220220
--archive_logs # (Archive old log files instead of deleting them.)
221+
--slow # (The option to slow down the automation.)
221222
--demo # (The option to visually see test actions as they occur.)
222223
--demo_sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
223224
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
sb.with_s3_logging = False
5353
sb.js_checking_on = False
5454
sb.is_pytest = False
55+
sb.slow_mode = False
5556
sb.demo_mode = False
5657
sb.demo_sleep = 1
5758
sb.message_duration = 2

help_docs/customizing_test_runs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ SeleniumBase provides additional Pytest command-line options for tests:
197197
--start_page=URL # (The starting URL for the web browser when tests begin.)
198198
--log_path=LOG_PATH # (The directory where log files get saved to.)
199199
--archive_logs # (Archive old log files instead of deleting them.)
200-
--demo_mode # (The option to visually see test actions as they occur.)
200+
--slow # (The option to slow down the automation.)
201+
--demo # (The option to visually see test actions as they occur.)
201202
--demo_sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
202203
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
203204
--message_duration=SECONDS # (The time length for Messenger alerts.)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pip>=19.3.1
22
setuptools>=41.6.0
33
setuptools-scm>=3.3.3
44
wheel>=0.33.6
5-
six>=1.12.0
5+
six>=1.13.0
66
nose>=1.3.7
77
ipdb>=0.12.2
88
idna==2.8

seleniumbase/fixtures/base_case.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def click(self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0):
167167
self.__demo_mode_pause_if_active()
168168
else:
169169
self.__demo_mode_pause_if_active(tiny=True)
170+
elif self.slow_mode:
171+
self.__slow_mode_pause_if_active()
170172

171173
def slow_click(self, selector, by=By.CSS_SELECTOR, timeout=None):
172174
""" Similar to click(), but pauses for a brief moment before clicking.
@@ -221,6 +223,8 @@ def double_click(self, selector, by=By.CSS_SELECTOR, timeout=None):
221223
self.__demo_mode_pause_if_active()
222224
else:
223225
self.__demo_mode_pause_if_active(tiny=True)
226+
elif self.slow_mode:
227+
self.__slow_mode_pause_if_active()
224228

225229
def click_chain(self, selectors_list, by=By.CSS_SELECTOR,
226230
timeout=None, spacing=0):
@@ -338,6 +342,8 @@ def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
338342
self.__demo_mode_pause_if_active()
339343
else:
340344
self.__demo_mode_pause_if_active(tiny=True)
345+
elif self.slow_mode:
346+
self.__slow_mode_pause_if_active()
341347

342348
def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
343349
""" The more-reliable version of driver.send_keys()
@@ -384,6 +390,8 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
384390
self.__demo_mode_pause_if_active()
385391
else:
386392
self.__demo_mode_pause_if_active(tiny=True)
393+
elif self.slow_mode:
394+
self.__slow_mode_pause_if_active()
387395

388396
def send_keys(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
389397
""" Same as add_text() """
@@ -437,13 +445,15 @@ def go_back(self):
437445
if self.browser == "safari":
438446
self.driver.refresh()
439447
self.wait_for_ready_state_complete()
448+
self.__demo_mode_pause_if_active()
440449

441450
def go_forward(self):
442451
self.__last_page_load_url = None
443452
self.driver.forward()
444453
if self.browser == "safari":
445454
self.driver.refresh()
446455
self.wait_for_ready_state_complete()
456+
self.__demo_mode_pause_if_active()
447457

448458
def is_element_present(self, selector, by=By.CSS_SELECTOR):
449459
selector, by = self.__recalculate_selector(selector, by)
@@ -626,6 +636,8 @@ def click_link_text(self, link_text, timeout=None):
626636
self.__demo_mode_pause_if_active()
627637
else:
628638
self.__demo_mode_pause_if_active(tiny=True)
639+
elif self.slow_mode:
640+
self.__slow_mode_pause_if_active()
629641

630642
def click_link(self, link_text, timeout=None):
631643
""" Same as self.click_link_text() """
@@ -738,6 +750,8 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
738750
self.__demo_mode_pause_if_active()
739751
else:
740752
self.__demo_mode_pause_if_active(tiny=True)
753+
elif self.slow_mode:
754+
self.__slow_mode_pause_if_active()
741755

742756
def get_text(self, selector, by=By.CSS_SELECTOR, timeout=None):
743757
if not timeout:
@@ -1094,6 +1108,8 @@ def hover_and_click(self, hover_selector, click_selector,
10941108
self.__demo_mode_pause_if_active()
10951109
else:
10961110
self.__demo_mode_pause_if_active(tiny=True)
1111+
elif self.slow_mode:
1112+
self.__slow_mode_pause_if_active()
10971113
return element
10981114

10991115
def hover_and_double_click(self, hover_selector, click_selector,
@@ -1141,6 +1157,8 @@ def hover_and_double_click(self, hover_selector, click_selector,
11411157
self.__demo_mode_pause_if_active()
11421158
else:
11431159
self.__demo_mode_pause_if_active(tiny=True)
1160+
elif self.slow_mode:
1161+
self.__slow_mode_pause_if_active()
11441162
return element
11451163

11461164
def __select_option(self, dropdown_selector, option,
@@ -1184,6 +1202,8 @@ def __select_option(self, dropdown_selector, option,
11841202
self.__demo_mode_pause_if_active()
11851203
else:
11861204
self.__demo_mode_pause_if_active(tiny=True)
1205+
elif self.slow_mode:
1206+
self.__slow_mode_pause_if_active()
11871207

11881208
def select_option_by_text(self, dropdown_selector, option,
11891209
dropdown_by=By.CSS_SELECTOR,
@@ -1604,7 +1624,7 @@ def scroll_to(self, selector, by=By.CSS_SELECTOR, timeout=None):
16041624
timeout = settings.SMALL_TIMEOUT
16051625
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
16061626
timeout = self.__get_new_timeout(timeout)
1607-
if self.demo_mode:
1627+
if self.demo_mode or self.slow_mode:
16081628
self.slow_scroll_to(selector, by=by, timeout=timeout)
16091629
return
16101630
element = self.wait_for_element_visible(
@@ -3634,14 +3654,22 @@ def __make_css_match_first_element_only(self, selector):
36343654

36353655
def __demo_mode_pause_if_active(self, tiny=False):
36363656
if self.demo_mode:
3657+
wait_time = settings.DEFAULT_DEMO_MODE_TIMEOUT
36373658
if self.demo_sleep:
36383659
wait_time = float(self.demo_sleep)
3639-
else:
3640-
wait_time = settings.DEFAULT_DEMO_MODE_TIMEOUT
36413660
if not tiny:
36423661
time.sleep(wait_time)
36433662
else:
36443663
time.sleep(wait_time / 3.4)
3664+
elif self.slow_mode:
3665+
self.__slow_mode_pause_if_active()
3666+
3667+
def __slow_mode_pause_if_active(self):
3668+
if self.slow_mode:
3669+
wait_time = settings.DEFAULT_DEMO_MODE_TIMEOUT
3670+
if self.demo_sleep:
3671+
wait_time = float(self.demo_sleep)
3672+
time.sleep(wait_time)
36453673

36463674
def __demo_mode_scroll_if_active(self, selector, by):
36473675
if self.demo_mode:
@@ -3651,6 +3679,19 @@ def __demo_mode_highlight_if_active(self, selector, by):
36513679
if self.demo_mode:
36523680
# Includes self.slow_scroll_to(selector, by=by) by default
36533681
self.highlight(selector, by=by)
3682+
elif self.slow_mode:
3683+
# Just do the slow scroll part of the highlight() method
3684+
selector, by = self.__recalculate_selector(selector, by)
3685+
element = self.wait_for_element_visible(
3686+
selector, by=by, timeout=settings.SMALL_TIMEOUT)
3687+
try:
3688+
self.__slow_scroll_to_element(element)
3689+
except (StaleElementReferenceException, ENI_Exception):
3690+
self.wait_for_ready_state_complete()
3691+
time.sleep(0.05)
3692+
element = self.wait_for_element_visible(
3693+
selector, by=by, timeout=settings.SMALL_TIMEOUT)
3694+
self.__slow_scroll_to_element(element)
36543695

36553696
def __scroll_to_element(self, element):
36563697
js_utils.scroll_to_element(self.driver, element)
@@ -3781,6 +3822,7 @@ def setUp(self, masterqa_mode=False):
37813822
self._testMethodName)
37823823
self.browser = sb_config.browser
37833824
self.data = sb_config.data
3825+
self.slow_mode = sb_config.slow_mode
37843826
self.demo_mode = sb_config.demo_mode
37853827
self.demo_sleep = sb_config.demo_sleep
37863828
self.highlights = sb_config.highlights
@@ -3991,6 +4033,7 @@ def tearDown(self):
39914033
You'll need to add the following line to the subclass's tearDown():
39924034
super(SubClassOfBaseCase, self).tearDown()
39934035
"""
4036+
self.__slow_mode_pause_if_active()
39944037
has_exception = False
39954038
if sys.version_info[0] >= 3 and hasattr(self, '_outcome'):
39964039
if hasattr(self._outcome, 'errors') and self._outcome.errors:

seleniumbase/plugins/pytest_plugin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def pytest_addoption(parser):
2929
--start_page=URL (The starting URL for the web browser when tests begin.)
3030
--log_path=LOG_PATH (The directory where log files get saved to.)
3131
--archive_logs (Archive old log files instead of deleting them.)
32+
--slow (The option to slow down the automation.)
3233
--demo (The option to visually see test actions as they occur.)
3334
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
3435
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
@@ -228,12 +229,17 @@ def pytest_addoption(parser):
228229
default=True,
229230
help="""This is used by the BaseCase class to tell apart
230231
pytest runs from nosetest runs. (Automatic)""")
232+
parser.addoption('--slow_mode', '--slow-mode', '--slow',
233+
action="store_true",
234+
dest='slow_mode',
235+
default=False,
236+
help="""Using this slows down the automation.""")
231237
parser.addoption('--demo_mode', '--demo-mode', '--demo',
232238
action="store_true",
233239
dest='demo_mode',
234240
default=False,
235-
help="""Using this slows down the automation so that
236-
you can see what it's actually doing.""")
241+
help="""Using this slows down the automation and lets you
242+
visually see what the tests are actually doing.""")
237243
parser.addoption('--demo_sleep', '--demo-sleep',
238244
action='store',
239245
dest='demo_sleep',
@@ -344,6 +350,7 @@ def pytest_configure(config):
344350
sb_config.database_env = config.getoption('database_env')
345351
sb_config.log_path = config.getoption('log_path')
346352
sb_config.archive_logs = config.getoption('archive_logs')
353+
sb_config.slow_mode = config.getoption('slow_mode')
347354
sb_config.demo_mode = config.getoption('demo_mode')
348355
sb_config.demo_sleep = config.getoption('demo_sleep')
349356
sb_config.highlights = config.getoption('highlights')

seleniumbase/plugins/selenium_plugin.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class SeleniumBrowser(Plugin):
2222
--headless (The option to run tests headlessly. The default on Linux OS.)
2323
--headed (The option to run tests with a GUI on Linux OS.)
2424
--start_page=URL (The starting URL for the web browser when tests begin.)
25-
--demo_mode (The option to visually see test actions as they occur.)
25+
--slow (The option to slow down the automation.)
26+
--demo (The option to visually see test actions as they occur.)
2627
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
2728
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
2829
--message_duration=SECONDS (The time length for Messenger alerts.)
@@ -146,13 +147,19 @@ def options(self, parser, env):
146147
help="""Designates the starting URL for the web browser
147148
when each test begins.
148149
Default: None.""")
150+
parser.add_option(
151+
'--slow_mode', '--slow-mode', '--slow',
152+
action="store_true",
153+
dest='slow_mode',
154+
default=False,
155+
help="""Using this slows down the automation.""")
149156
parser.add_option(
150157
'--demo_mode', '--demo-mode', '--demo',
151158
action="store_true",
152159
dest='demo_mode',
153160
default=False,
154-
help="""Using this slows down the automation so that
155-
you can see what it's actually doing.""")
161+
help="""Using this slows down the automation and lets you
162+
visually see what the tests are actually doing.""")
156163
parser.add_option(
157164
'--demo_sleep', '--demo-sleep',
158165
action='store',
@@ -265,6 +272,7 @@ def beforeTest(self, test):
265272
test.test.extension_dir = self.options.extension_dir
266273
test.test.proxy_string = self.options.proxy_string
267274
test.test.user_agent = self.options.user_agent
275+
test.test.slow_mode = self.options.slow_mode
268276
test.test.demo_mode = self.options.demo_mode
269277
test.test.demo_sleep = self.options.demo_sleep
270278
test.test.highlights = self.options.highlights

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.32.21',
48+
version='1.32.22',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)