Skip to content

Commit 4d1adb6

Browse files
committed
Update Tour Mode
1 parent 7e9b0fb commit 4d1adb6

File tree

4 files changed

+61
-57
lines changed

4 files changed

+61
-57
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, pgkeys=False)
658-
# Duplicates: self.start_tour(name=None, interval=0, pgkeys=False):
657+
self.play_tour(name=None, interval=0)
658+
# Duplicates: self.start_tour(name=None, interval=0):
659659

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

seleniumbase/core/tour_helper.py

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
EXPORTED_TOURS_FOLDER = constants.Tours.EXPORTED_TOURS_FOLDER
1515

1616

17-
def activate_bootstrap(driver, pgkeys=False):
17+
def activate_bootstrap(driver):
1818
"""Allows you to use Bootstrap Tours with SeleniumBase
1919
http://bootstraptour.com/
2020
"""
2121
bootstrap_tour_css = constants.BootstrapTour.MIN_CSS
2222
bootstrap_tour_js = constants.BootstrapTour.MIN_JS
23-
if pgkeys:
24-
bootstrap_tour_js = constants.BootstrapTour.MIN_JS_SB
2523

2624
verify_script = """// Verify Bootstrap Tour activated
2725
var tour2 = new Tour({
@@ -58,15 +56,13 @@ def is_bootstrap_activated(driver):
5856
return False
5957

6058

61-
def activate_driverjs(driver, pgkeys=False):
59+
def activate_driverjs(driver):
6260
"""Allows you to use DriverJS Tours with SeleniumBase
6361
https://kamranahmed.info/driver.js/
6462
"""
6563
backdrop_style = style_sheet.get_dt_backdrop_style()
6664
driverjs_css = constants.DriverJS.MIN_CSS
6765
driverjs_js = constants.DriverJS.MIN_JS
68-
if pgkeys:
69-
driverjs_js = constants.DriverJS.MIN_JS_SB
7066

7167
verify_script = """// Verify DriverJS activated
7268
var driverjs2 = Driver.name;
@@ -148,14 +144,12 @@ def is_hopscotch_activated(driver):
148144
return False
149145

150146

151-
def activate_introjs(driver, pgkeys=False):
147+
def activate_introjs(driver):
152148
"""Allows you to use IntroJS Tours with SeleniumBase
153149
https://introjs.com/
154150
"""
155151
intro_css = constants.IntroJS.MIN_CSS
156152
intro_js = constants.IntroJS.MIN_JS
157-
if pgkeys:
158-
intro_js = constants.IntroJS.MIN_JS_SB
159153

160154
theme_color = sb_config.introjs_theme_color
161155
hover_color = sb_config.introjs_hover_color
@@ -269,6 +263,13 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
269263
// Start the tour
270264
tour.start();
271265
$tour = tour;"""
266+
instructions += """
267+
document.body.addEventListener('keyup', function (event) {
268+
if (event.key === 'PageUp' || event.key === 'ArrowLeft') {
269+
Shepherd.activeTour.back(); }
270+
if (event.key === 'PageDown' || event.key === 'ArrowRight') {
271+
Shepherd.activeTour.next(); }
272+
})"""
272273
autoplay = False
273274
if interval and interval > 0:
274275
autoplay = True
@@ -302,6 +303,16 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
302303
"" % selector
303304
)
304305
driver.execute_script(instructions)
306+
try:
307+
page_actions.wait_for_element_visible(
308+
driver, "a.tour-button-right", by="css selector", timeout=1.2
309+
)
310+
except Exception:
311+
pass
312+
try:
313+
driver.execute_script('document.activeElement.blur();')
314+
except Exception:
315+
pass
305316
tour_on = True
306317
if autoplay:
307318
start_ms = time.time() * 1000.0
@@ -389,13 +400,7 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
389400

390401

391402
def play_bootstrap_tour(
392-
driver,
393-
tour_steps,
394-
browser,
395-
msg_dur,
396-
name=None,
397-
interval=0,
398-
pgkeys=False,
403+
driver, tour_steps, browser, msg_dur, name=None, interval=0
399404
):
400405
"""Plays a Bootstrap tour on the current website."""
401406
instructions = ""
@@ -410,18 +415,15 @@ def play_bootstrap_tour(
410415
tour.restart();
411416
// Save for later
412417
$tour = tour;"""
413-
414418
if interval and interval > 0:
415419
if interval < 1:
416420
interval = 1
417421
interval = str(float(interval) * 1000.0)
418422
instructions = instructions.replace(
419423
"duration: 0,", "duration: %s," % interval
420424
)
421-
422425
if not is_bootstrap_activated(driver):
423-
activate_bootstrap(driver, pgkeys)
424-
426+
activate_bootstrap(driver)
425427
if len(tour_steps[name]) > 1:
426428
try:
427429
if "element: " in tour_steps[name][1]:
@@ -447,7 +449,6 @@ def play_bootstrap_tour(
447449
"Exiting due to failure on first tour step!"
448450
"" % selector
449451
)
450-
451452
driver.execute_script(instructions)
452453
tour_on = True
453454
try:
@@ -497,13 +498,7 @@ def play_bootstrap_tour(
497498

498499

499500
def play_driverjs_tour(
500-
driver,
501-
tour_steps,
502-
browser,
503-
msg_dur,
504-
name=None,
505-
interval=0,
506-
pgkeys=False,
501+
driver, tour_steps, browser, msg_dur, name=None, interval=0
507502
):
508503
"""Plays a DriverJS tour on the current website."""
509504
instructions = ""
@@ -514,6 +509,11 @@ def play_driverjs_tour(
514509
// Start the tour!
515510
tour.start();
516511
$tour = tour;"""
512+
instructions += """
513+
document.body.addEventListener('keyup', function (event) {
514+
if (event.key === 'PageUp') { $tour.movePrevious(); }
515+
if (event.key === 'PageDown') { $tour.moveNext(); }
516+
})"""
517517
autoplay = False
518518
if interval and interval > 0:
519519
autoplay = True
@@ -522,7 +522,7 @@ def play_driverjs_tour(
522522
interval = 0.5
523523

524524
if not is_driverjs_activated(driver):
525-
activate_driverjs(driver, pgkeys)
525+
activate_driverjs(driver)
526526

527527
if len(tour_steps[name]) > 1:
528528
try:
@@ -641,6 +641,13 @@ def play_hopscotch_tour(
641641
// Start the tour!
642642
hopscotch.startTour(tour);
643643
$tour = hopscotch;"""
644+
instructions += """
645+
document.body.addEventListener('keyup', function (event) {
646+
if (event.key === 'PageUp' || event.key === 'ArrowLeft') {
647+
$tour.prevStep(); }
648+
if (event.key === 'PageDown' || event.key === 'ArrowRight') {
649+
$tour.nextStep(); }
650+
})"""
644651
autoplay = False
645652
if interval and interval > 0:
646653
autoplay = True
@@ -678,6 +685,16 @@ def play_hopscotch_tour(
678685
)
679686

680687
driver.execute_script(instructions)
688+
try:
689+
page_actions.wait_for_element_visible(
690+
driver, "button.hopscotch-next", by="css selector", timeout=1.2
691+
)
692+
except Exception:
693+
pass
694+
try:
695+
driver.execute_script('document.activeElement.blur();')
696+
except Exception:
697+
pass
681698
tour_on = True
682699
if autoplay:
683700
start_ms = time.time() * 1000.0
@@ -749,13 +766,7 @@ def play_hopscotch_tour(
749766

750767

751768
def play_introjs_tour(
752-
driver,
753-
tour_steps,
754-
browser,
755-
msg_dur,
756-
name=None,
757-
interval=0,
758-
pgkeys=False,
769+
driver, tour_steps, browser, msg_dur, name=None, interval=0
759770
):
760771
"""Plays an IntroJS tour on the current website."""
761772
instructions = ""
@@ -779,6 +790,11 @@ def play_introjs_tour(
779790
// Start the tour
780791
startIntro();
781792
"""
793+
instructions += """
794+
document.body.addEventListener('keyup', function (event) {
795+
if (event.key === 'PageUp') { $tour.previousStep(); }
796+
if (event.key === 'PageDown') { $tour.nextStep(); }
797+
})"""
782798
autoplay = False
783799
if interval and interval > 0:
784800
autoplay = True
@@ -787,7 +803,7 @@ def play_introjs_tour(
787803
interval = 0.5
788804

789805
if not is_introjs_activated(driver):
790-
activate_introjs(driver, pgkeys)
806+
activate_introjs(driver)
791807

792808
if len(tour_steps[name]) > 1:
793809
try:

seleniumbase/fixtures/base_case.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11695,17 +11695,13 @@ def __add_introjs_tour_step(
1169511695
)
1169611696
self._tour_steps[name].append(step)
1169711697

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

1171111707
if self.headless or self.headless2 or self.xvfb:
@@ -11727,7 +11723,6 @@ def play_tour(self, name=None, interval=0, pgkeys=False):
1172711723
self.message_duration,
1172811724
name=name,
1172911725
interval=interval,
11730-
pgkeys=pgkeys,
1173111726
)
1173211727
elif "DriverJS" in self._tour_steps[name][0]:
1173311728
tour_helper.play_driverjs_tour(
@@ -11737,7 +11732,6 @@ def play_tour(self, name=None, interval=0, pgkeys=False):
1173711732
self.message_duration,
1173811733
name=name,
1173911734
interval=interval,
11740-
pgkeys=pgkeys,
1174111735
)
1174211736
elif "Hopscotch" in self._tour_steps[name][0]:
1174311737
tour_helper.play_hopscotch_tour(
@@ -11756,7 +11750,6 @@ def play_tour(self, name=None, interval=0, pgkeys=False):
1175611750
self.message_duration,
1175711751
name=name,
1175811752
interval=interval,
11759-
pgkeys=pgkeys,
1176011753
)
1176111754
else:
1176211755
tour_helper.play_shepherd_tour(
@@ -11767,9 +11760,9 @@ def play_tour(self, name=None, interval=0, pgkeys=False):
1176711760
interval=interval,
1176811761
)
1176911762

11770-
def start_tour(self, name=None, interval=0, pgkeys=False):
11763+
def start_tour(self, name=None, interval=0):
1177111764
"""Same as self.play_tour()"""
11772-
self.play_tour(name=name, interval=interval, pgkeys=pgkeys)
11765+
self.play_tour(name=name, interval=interval)
1177311766

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

seleniumbase/fixtures/constants.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,15 @@ class BootstrapTour:
240240
LIB = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tour"
241241
VER = "0.12.0"
242242
MIN_CSS = "%s/%s/css/bootstrap-tour-standalone.min.css" % (LIB, VER)
243-
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-
)
243+
# MIN_JS = "%s/%s/js/bootstrap-tour-standalone.min.js" % (LIB, VER)
244+
MIN_JS = "https://seleniumbase.github.io/cdn/js/bootstraptour.min.js"
248245

249246

250247
class DriverJS:
251248
LIB = "https://cdn.jsdelivr.net/npm/driver.js"
252249
VER = "0.9.8"
253250
MIN_CSS = "%s@%s/dist/driver.min.css" % (LIB, VER)
254251
MIN_JS = "%s@%s/dist/driver.min.js" % (LIB, VER)
255-
MIN_JS_SB = "https://seleniumbase.github.io/cdn/js/driver.min.js"
256252

257253

258254
class Hopscotch:
@@ -269,7 +265,6 @@ class IntroJS:
269265
"intro.js@%s/minified/introjs.min.css" % VER
270266
)
271267
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"
273268

274269

275270
class TourColor:

0 commit comments

Comments
 (0)