14
14
EXPORTED_TOURS_FOLDER = constants .Tours .EXPORTED_TOURS_FOLDER
15
15
16
16
17
- def activate_bootstrap (driver , pgkeys = False ):
17
+ def activate_bootstrap (driver ):
18
18
"""Allows you to use Bootstrap Tours with SeleniumBase
19
19
http://bootstraptour.com/
20
20
"""
21
21
bootstrap_tour_css = constants .BootstrapTour .MIN_CSS
22
22
bootstrap_tour_js = constants .BootstrapTour .MIN_JS
23
- if pgkeys :
24
- bootstrap_tour_js = constants .BootstrapTour .MIN_JS_SB
25
23
26
24
verify_script = """// Verify Bootstrap Tour activated
27
25
var tour2 = new Tour({
@@ -58,15 +56,13 @@ def is_bootstrap_activated(driver):
58
56
return False
59
57
60
58
61
- def activate_driverjs (driver , pgkeys = False ):
59
+ def activate_driverjs (driver ):
62
60
"""Allows you to use DriverJS Tours with SeleniumBase
63
61
https://kamranahmed.info/driver.js/
64
62
"""
65
63
backdrop_style = style_sheet .get_dt_backdrop_style ()
66
64
driverjs_css = constants .DriverJS .MIN_CSS
67
65
driverjs_js = constants .DriverJS .MIN_JS
68
- if pgkeys :
69
- driverjs_js = constants .DriverJS .MIN_JS_SB
70
66
71
67
verify_script = """// Verify DriverJS activated
72
68
var driverjs2 = Driver.name;
@@ -148,14 +144,12 @@ def is_hopscotch_activated(driver):
148
144
return False
149
145
150
146
151
- def activate_introjs (driver , pgkeys = False ):
147
+ def activate_introjs (driver ):
152
148
"""Allows you to use IntroJS Tours with SeleniumBase
153
149
https://introjs.com/
154
150
"""
155
151
intro_css = constants .IntroJS .MIN_CSS
156
152
intro_js = constants .IntroJS .MIN_JS
157
- if pgkeys :
158
- intro_js = constants .IntroJS .MIN_JS_SB
159
153
160
154
theme_color = sb_config .introjs_theme_color
161
155
hover_color = sb_config .introjs_hover_color
@@ -269,6 +263,13 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
269
263
// Start the tour
270
264
tour.start();
271
265
$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
+ })"""
272
273
autoplay = False
273
274
if interval and interval > 0 :
274
275
autoplay = True
@@ -302,6 +303,16 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
302
303
"" % selector
303
304
)
304
305
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
305
316
tour_on = True
306
317
if autoplay :
307
318
start_ms = time .time () * 1000.0
@@ -389,13 +400,7 @@ def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=0):
389
400
390
401
391
402
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
399
404
):
400
405
"""Plays a Bootstrap tour on the current website."""
401
406
instructions = ""
@@ -410,18 +415,15 @@ def play_bootstrap_tour(
410
415
tour.restart();
411
416
// Save for later
412
417
$tour = tour;"""
413
-
414
418
if interval and interval > 0 :
415
419
if interval < 1 :
416
420
interval = 1
417
421
interval = str (float (interval ) * 1000.0 )
418
422
instructions = instructions .replace (
419
423
"duration: 0," , "duration: %s," % interval
420
424
)
421
-
422
425
if not is_bootstrap_activated (driver ):
423
- activate_bootstrap (driver , pgkeys )
424
-
426
+ activate_bootstrap (driver )
425
427
if len (tour_steps [name ]) > 1 :
426
428
try :
427
429
if "element: " in tour_steps [name ][1 ]:
@@ -447,7 +449,6 @@ def play_bootstrap_tour(
447
449
"Exiting due to failure on first tour step!"
448
450
"" % selector
449
451
)
450
-
451
452
driver .execute_script (instructions )
452
453
tour_on = True
453
454
try :
@@ -497,13 +498,7 @@ def play_bootstrap_tour(
497
498
498
499
499
500
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
507
502
):
508
503
"""Plays a DriverJS tour on the current website."""
509
504
instructions = ""
@@ -514,6 +509,11 @@ def play_driverjs_tour(
514
509
// Start the tour!
515
510
tour.start();
516
511
$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
+ })"""
517
517
autoplay = False
518
518
if interval and interval > 0 :
519
519
autoplay = True
@@ -522,7 +522,7 @@ def play_driverjs_tour(
522
522
interval = 0.5
523
523
524
524
if not is_driverjs_activated (driver ):
525
- activate_driverjs (driver , pgkeys )
525
+ activate_driverjs (driver )
526
526
527
527
if len (tour_steps [name ]) > 1 :
528
528
try :
@@ -641,6 +641,13 @@ def play_hopscotch_tour(
641
641
// Start the tour!
642
642
hopscotch.startTour(tour);
643
643
$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
+ })"""
644
651
autoplay = False
645
652
if interval and interval > 0 :
646
653
autoplay = True
@@ -678,6 +685,16 @@ def play_hopscotch_tour(
678
685
)
679
686
680
687
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
681
698
tour_on = True
682
699
if autoplay :
683
700
start_ms = time .time () * 1000.0
@@ -749,13 +766,7 @@ def play_hopscotch_tour(
749
766
750
767
751
768
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
759
770
):
760
771
"""Plays an IntroJS tour on the current website."""
761
772
instructions = ""
@@ -779,6 +790,11 @@ def play_introjs_tour(
779
790
// Start the tour
780
791
startIntro();
781
792
"""
793
+ instructions += """
794
+ document.body.addEventListener('keyup', function (event) {
795
+ if (event.key === 'PageUp') { $tour.previousStep(); }
796
+ if (event.key === 'PageDown') { $tour.nextStep(); }
797
+ })"""
782
798
autoplay = False
783
799
if interval and interval > 0 :
784
800
autoplay = True
@@ -787,7 +803,7 @@ def play_introjs_tour(
787
803
interval = 0.5
788
804
789
805
if not is_introjs_activated (driver ):
790
- activate_introjs (driver , pgkeys )
806
+ activate_introjs (driver )
791
807
792
808
if len (tour_steps [name ]) > 1 :
793
809
try :
0 commit comments