Skip to content

Commit f3ed6b9

Browse files
committed
Add option to use the "Page-Up"/"Page-Down" keys for Tours
1 parent 212a77f commit f3ed6b9

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ self.set_introjs_colors(theme_color=None, hover_color=None)
654654
self.add_tour_step(message, selector=None, name=None,
655655
title=None, theme=None, alignment=None)
656656

657-
self.play_tour(name=None, interval=0)
658-
# Duplicates: self.start_tour(name=None, interval=0):
657+
self.play_tour(name=None, interval=0, pgkeys=False)
658+
# Duplicates: self.start_tour(name=None, interval=0, pgkeys=False):
659659

660660
self.export_tour(name=None, filename="my_tour.js", url=None)
661661

seleniumbase/core/tour_helper.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
This module contains methods for running website tours.
3-
These helper methods SHOULD NOT be called directly from tests.
4-
"""
1+
"""This module contains methods for running website tours.
2+
These helper methods SHOULD NOT be called directly from tests."""
53
import os
64
import re
75
import textwrap
@@ -16,12 +14,14 @@
1614
EXPORTED_TOURS_FOLDER = constants.Tours.EXPORTED_TOURS_FOLDER
1715

1816

19-
def activate_bootstrap(driver):
17+
def activate_bootstrap(driver, pgkeys=False):
2018
"""Allows you to use Bootstrap Tours with SeleniumBase
2119
http://bootstraptour.com/
2220
"""
2321
bootstrap_tour_css = constants.BootstrapTour.MIN_CSS
2422
bootstrap_tour_js = constants.BootstrapTour.MIN_JS
23+
if pgkeys:
24+
bootstrap_tour_js = constants.BootstrapTour.MIN_JS_SB
2525

2626
verify_script = """// Verify Bootstrap Tour activated
2727
var tour2 = new Tour({
@@ -58,19 +58,20 @@ def is_bootstrap_activated(driver):
5858
return False
5959

6060

61-
def activate_driverjs(driver):
61+
def activate_driverjs(driver, pgkeys=False):
6262
"""Allows you to use DriverJS Tours with SeleniumBase
6363
https://kamranahmed.info/driver.js/
6464
"""
6565
backdrop_style = style_sheet.get_dt_backdrop_style()
6666
driverjs_css = constants.DriverJS.MIN_CSS
6767
driverjs_js = constants.DriverJS.MIN_JS
68+
if pgkeys:
69+
driverjs_js = constants.DriverJS.MIN_JS_SB
6870

6971
verify_script = """// Verify DriverJS activated
7072
var driverjs2 = Driver.name;
7173
"""
7274

73-
activate_bootstrap(driver)
7475
js_utils.wait_for_ready_state_complete(driver)
7576
js_utils.wait_for_angularjs(driver)
7677
js_utils.add_css_style(driver, backdrop_style)
@@ -115,7 +116,6 @@ def activate_hopscotch(driver):
115116
var hops = hopscotch.isActive;
116117
"""
117118

118-
activate_bootstrap(driver)
119119
js_utils.wait_for_ready_state_complete(driver)
120120
js_utils.wait_for_angularjs(driver)
121121
js_utils.add_css_style(driver, backdrop_style)
@@ -148,12 +148,14 @@ def is_hopscotch_activated(driver):
148148
return False
149149

150150

151-
def activate_introjs(driver):
151+
def activate_introjs(driver, pgkeys=False):
152152
"""Allows you to use IntroJS Tours with SeleniumBase
153153
https://introjs.com/
154154
"""
155155
intro_css = constants.IntroJS.MIN_CSS
156156
intro_js = constants.IntroJS.MIN_JS
157+
if pgkeys:
158+
intro_js = constants.IntroJS.MIN_JS_SB
157159

158160
theme_color = sb_config.introjs_theme_color
159161
hover_color = sb_config.introjs_hover_color
@@ -169,7 +171,6 @@ def activate_introjs(driver):
169171
var intro2 = introJs();
170172
"""
171173

172-
activate_bootstrap(driver)
173174
js_utils.wait_for_ready_state_complete(driver)
174175
js_utils.wait_for_angularjs(driver)
175176
js_utils.add_css_style(driver, backdrop_style)
@@ -218,7 +219,6 @@ def activate_shepherd(driver):
218219
sh_style = style_sheet.get_sh_style_test()
219220
backdrop_style = style_sheet.get_sh_backdrop_style()
220221

221-
activate_bootstrap(driver)
222222
js_utils.wait_for_ready_state_complete(driver)
223223
js_utils.wait_for_angularjs(driver)
224224
js_utils.add_css_style(driver, backdrop_style)
@@ -389,7 +389,13 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
389389

390390

391391
def play_bootstrap_tour(
392-
driver, tour_steps, browser, msg_dur, name=None, interval=0
392+
driver,
393+
tour_steps,
394+
browser,
395+
msg_dur,
396+
name=None,
397+
interval=0,
398+
pgkeys=False,
393399
):
394400
"""Plays a Bootstrap tour on the current website."""
395401
instructions = ""
@@ -414,7 +420,7 @@ def play_bootstrap_tour(
414420
)
415421

416422
if not is_bootstrap_activated(driver):
417-
activate_bootstrap(driver)
423+
activate_bootstrap(driver, pgkeys)
418424

419425
if len(tour_steps[name]) > 1:
420426
try:
@@ -444,14 +450,24 @@ def play_bootstrap_tour(
444450

445451
driver.execute_script(instructions)
446452
tour_on = True
453+
try:
454+
page_actions.wait_for_element_visible(
455+
driver, ".tour-tour", by="css selector", timeout=1.2
456+
)
457+
except Exception:
458+
pass
459+
try:
460+
driver.execute_script('document.activeElement.blur();')
461+
except Exception:
462+
pass
447463
while tour_on:
448464
try:
449465
time.sleep(0.01)
450466
if browser != "firefox":
451467
result = driver.execute_script("return $tour.ended()")
452468
else:
453469
page_actions.wait_for_element_present(
454-
driver, ".tour-tour", by="css selector", timeout=0.65
470+
driver, ".tour-tour", by="css selector", timeout=0.48
455471
)
456472
result = False
457473
except Exception:
@@ -467,7 +483,7 @@ def play_bootstrap_tour(
467483
result = driver.execute_script("return $tour.ended()")
468484
else:
469485
page_actions.wait_for_element_present(
470-
driver, ".tour-tour", by="css selector", timeout=0.65
486+
driver, ".tour-tour", by="css selector", timeout=0.48
471487
)
472488
result = False
473489
if result is False:
@@ -481,7 +497,13 @@ def play_bootstrap_tour(
481497

482498

483499
def play_driverjs_tour(
484-
driver, tour_steps, browser, msg_dur, name=None, interval=0
500+
driver,
501+
tour_steps,
502+
browser,
503+
msg_dur,
504+
name=None,
505+
interval=0,
506+
pgkeys=False,
485507
):
486508
"""Plays a DriverJS tour on the current website."""
487509
instructions = ""
@@ -500,7 +522,7 @@ def play_driverjs_tour(
500522
interval = 0.5
501523

502524
if not is_driverjs_activated(driver):
503-
activate_driverjs(driver)
525+
activate_driverjs(driver, pgkeys)
504526

505527
if len(tour_steps[name]) > 1:
506528
try:
@@ -727,7 +749,13 @@ def play_hopscotch_tour(
727749

728750

729751
def play_introjs_tour(
730-
driver, tour_steps, browser, msg_dur, name=None, interval=0
752+
driver,
753+
tour_steps,
754+
browser,
755+
msg_dur,
756+
name=None,
757+
interval=0,
758+
pgkeys=False,
731759
):
732760
"""Plays an IntroJS tour on the current website."""
733761
instructions = ""
@@ -759,7 +787,7 @@ def play_introjs_tour(
759787
interval = 0.5
760788

761789
if not is_introjs_activated(driver):
762-
activate_introjs(driver)
790+
activate_introjs(driver, pgkeys)
763791

764792
if len(tour_steps[name]) > 1:
765793
try:

seleniumbase/fixtures/base_case.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11692,13 +11692,17 @@ def __add_introjs_tour_step(
1169211692
)
1169311693
self._tour_steps[name].append(step)
1169411694

11695-
def play_tour(self, name=None, interval=0):
11695+
def play_tour(self, name=None, interval=0, pgkeys=False):
1169611696
"""Plays a tour on the current website.
1169711697
@Params
1169811698
name - If creating multiple tours at the same time,
1169911699
use this to select the tour you wish to add steps to.
1170011700
interval - The delay time between autoplaying tour steps. (Seconds)
11701-
If set to 0 (default), the tour is fully manual control."""
11701+
If set to 0 (default), the tour is fully manual control.
11702+
pgkeys - Lets you control tours using the page-up / page-down keys.
11703+
This only works on Bootstrap, DriverJS, and IntroJS tours.
11704+
If the tour is part of a presentation that uses a clicker,
11705+
then you'll need this enabled for the clicker to work."""
1170211706
from seleniumbase.core import tour_helper
1170311707

1170411708
if self.headless or self.headless2 or self.xvfb:
@@ -11720,6 +11724,7 @@ def play_tour(self, name=None, interval=0):
1172011724
self.message_duration,
1172111725
name=name,
1172211726
interval=interval,
11727+
pgkeys=pgkeys,
1172311728
)
1172411729
elif "DriverJS" in self._tour_steps[name][0]:
1172511730
tour_helper.play_driverjs_tour(
@@ -11729,6 +11734,7 @@ def play_tour(self, name=None, interval=0):
1172911734
self.message_duration,
1173011735
name=name,
1173111736
interval=interval,
11737+
pgkeys=pgkeys,
1173211738
)
1173311739
elif "Hopscotch" in self._tour_steps[name][0]:
1173411740
tour_helper.play_hopscotch_tour(
@@ -11747,6 +11753,7 @@ def play_tour(self, name=None, interval=0):
1174711753
self.message_duration,
1174811754
name=name,
1174911755
interval=interval,
11756+
pgkeys=pgkeys,
1175011757
)
1175111758
else:
1175211759
tour_helper.play_shepherd_tour(
@@ -11757,9 +11764,9 @@ def play_tour(self, name=None, interval=0):
1175711764
interval=interval,
1175811765
)
1175911766

11760-
def start_tour(self, name=None, interval=0):
11767+
def start_tour(self, name=None, interval=0, pgkeys=False):
1176111768
"""Same as self.play_tour()"""
11762-
self.play_tour(name=name, interval=interval)
11769+
self.play_tour(name=name, interval=interval, pgkeys=pgkeys)
1176311770

1176411771
def export_tour(self, name=None, filename="my_tour.js", url=None):
1176511772
"""Exports a tour as a JS file.

seleniumbase/fixtures/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,18 @@ class BootstrapTour:
241241
VER = "0.12.0"
242242
MIN_CSS = "%s/%s/css/bootstrap-tour-standalone.min.css" % (LIB, VER)
243243
MIN_JS = "%s/%s/js/bootstrap-tour-standalone.min.js" % (LIB, VER)
244+
MIN_JS_SB = (
245+
"https://seleniumbase.github.io/cdn/js/"
246+
"bootstrap-tour-standalone.min.js"
247+
)
244248

245249

246250
class DriverJS:
247251
LIB = "https://cdn.jsdelivr.net/npm/driver.js"
248252
VER = "0.9.8"
249253
MIN_CSS = "%s@%s/dist/driver.min.css" % (LIB, VER)
250254
MIN_JS = "%s@%s/dist/driver.min.js" % (LIB, VER)
255+
MIN_JS_SB = "https://seleniumbase.github.io/cdn/js/driver.min.js"
251256

252257

253258
class Hopscotch:
@@ -264,6 +269,7 @@ class IntroJS:
264269
"intro.js@%s/minified/introjs.min.css" % VER
265270
)
266271
MIN_JS = "https://cdn.jsdelivr.net/npm/intro.js@%s/intro.min.js" % VER
272+
MIN_JS_SB = "https://seleniumbase.github.io/cdn/js/intro.min.js"
267273

268274

269275
class TourColor:

0 commit comments

Comments
 (0)