@@ -1030,15 +1030,24 @@ def add_tour_step(self, message, selector=None, name=None,
1030
1030
1031
1031
self ._tour_steps [name ].append (step )
1032
1032
1033
- def play_tour (self , name = None ):
1033
+ def play_tour (self , name = None , interval = 0 ):
1034
1034
""" Plays a tour on the current website.
1035
1035
@Params
1036
1036
name - If creating multiple tours, use this to select the
1037
1037
tour you wish to play.
1038
+ interval - The delay time between autoplaying tour steps.
1039
+ If set to 0 (default), the tour is fully manual control.
1038
1040
"""
1039
1041
if self .headless :
1040
1042
return # Tours should not run in headless mode.
1041
1043
1044
+ autoplay = False
1045
+ if interval and interval > 0 :
1046
+ autoplay = True
1047
+ interval = float (interval )
1048
+ if interval < 0.5 :
1049
+ interval = 0.5
1050
+
1042
1051
if not name :
1043
1052
name = "default"
1044
1053
if name not in self ._tour_steps :
@@ -1070,6 +1079,11 @@ def play_tour(self, name=None):
1070
1079
1071
1080
self .execute_script (instructions )
1072
1081
tour_on = True
1082
+ if autoplay :
1083
+ start_ms = time .time () * 1000.0
1084
+ stop_ms = start_ms + (interval * 1000.0 )
1085
+ latest_element = None
1086
+ latest_text = None
1073
1087
while tour_on :
1074
1088
try :
1075
1089
time .sleep (0.01 )
@@ -1080,6 +1094,33 @@ def play_tour(self, name=None):
1080
1094
result = None
1081
1095
if result :
1082
1096
tour_on = True
1097
+ if autoplay :
1098
+ try :
1099
+ element = self .execute_script (
1100
+ "Shepherd.activeTour.currentStep"
1101
+ ".options.attachTo.element" )
1102
+ shep_text = self .execute_script (
1103
+ "Shepherd.activeTour.currentStep.options.text" )
1104
+ except Exception :
1105
+ continue
1106
+ now_ms = time .time () * 1000.0
1107
+ if now_ms >= stop_ms :
1108
+ if ((element == latest_element ) and
1109
+ (shep_text == latest_text )):
1110
+ self .execute_script ("Shepherd.activeTour.next()" )
1111
+ try :
1112
+ latest_element = self .execute_script (
1113
+ "Shepherd.activeTour.currentStep"
1114
+ ".options.attachTo.element" )
1115
+ latest_text = self .execute_script (
1116
+ "Shepherd.activeTour.currentStep"
1117
+ ".options.text" )
1118
+ start_ms = time .time () * 1000.0
1119
+ stop_ms = start_ms + (interval * 1000.0 )
1120
+ except Exception :
1121
+ pass
1122
+ continue
1123
+
1083
1124
else :
1084
1125
try :
1085
1126
time .sleep (0.01 )
@@ -1097,6 +1138,9 @@ def play_tour(self, name=None):
1097
1138
duration = settings .SMALL_TIMEOUT )
1098
1139
time .sleep (0.1 )
1099
1140
self .execute_script ("Shepherd.activeTour.next()" )
1141
+ if autoplay :
1142
+ start_ms = time .time () * 1000.0
1143
+ stop_ms = start_ms + (interval * 1000.0 )
1100
1144
tour_on = True
1101
1145
except Exception :
1102
1146
tour_on = False
0 commit comments