@@ -720,40 +720,46 @@ def maximize_window(self):
720
720
721
721
def add_css_link (self , css_link ):
722
722
script_to_add_css = (
723
- """function injectCSS() {
723
+ """function injectCSS(css ) {
724
724
var head = document.getElementsByTagName("head")[0];
725
725
var link = document.createElement("link");
726
726
link.rel = "stylesheet";
727
727
link.type = "text/css";
728
- link.href = "%s" ;
728
+ link.href = css ;
729
729
link.crossorigin = "anonymous";
730
730
head.appendChild(link);
731
731
}
732
- injectCSS();""" )
732
+ injectCSS("%s");""" )
733
+ css_link = self .__escape_quotes_if_needed (css_link )
733
734
self .execute_script (script_to_add_css % css_link )
734
735
735
736
def add_js_link (self , js_link ):
736
737
script_to_add_js = (
737
- """function injectJS() {
738
+ """function injectJS(link ) {
738
739
var head = document.getElementsByTagName("head")[0];
739
740
var script = document.createElement("script");
740
- script.src = "%s" ;
741
+ script.src = link ;
741
742
script.defer;
743
+ script.type="text/javascript";
742
744
script.crossorigin = "anonymous";
743
745
script.onload = function() { null };
744
746
head.appendChild(script);
745
747
}
746
- injectJS();""" )
748
+ injectJS("%s");""" )
749
+ js_link = self .__escape_quotes_if_needed (js_link )
747
750
self .execute_script (script_to_add_js % js_link )
748
751
749
752
def add_css_style (self , css_style ):
750
753
add_css_style_script = (
751
- '''var h = document.getElementsByTagName('head').item(0);'''
752
- '''var s = document.createElement("style");'''
753
- '''s.type = "text/css";'''
754
- '''s.appendChild(document.createTextNode("%s"));'''
755
- '''h.appendChild(s);''' )
756
- css_style = re .escape (css_style )
754
+ """function injectStyle(css) {
755
+ var head = document.getElementsByTagName("head")[0];
756
+ var style = document.createElement("style");
757
+ style.type = "text/css";
758
+ style.appendChild(document.createTextNode(css));
759
+ head.appendChild(style);
760
+ }
761
+ injectStyle("%s");""" )
762
+ css_style = css_style .replace ('\n ' , '' )
757
763
css_style = self .__escape_quotes_if_needed (css_style )
758
764
self .execute_script (add_css_style_script % css_style )
759
765
@@ -800,7 +806,11 @@ def activate_jquery(self):
800
806
# jQuery is not currently defined. Let's proceed by defining it.
801
807
pass
802
808
jquery_js = constants .JQuery .MIN_JS
803
- self .add_js_link (jquery_js )
809
+ activate_jquery_script = (
810
+ '''var script = document.createElement('script');'''
811
+ '''script.src = "%s";document.getElementsByTagName('head')[0]'''
812
+ '''.appendChild(script);''' % jquery_js )
813
+ self .execute_script (activate_jquery_script )
804
814
for x in range (int (settings .MINI_TIMEOUT * 10.0 )):
805
815
# jQuery needs a small amount of time to activate.
806
816
try :
@@ -966,8 +976,6 @@ def __activate_shepherd(self):
966
976
sh_theme_sq_css = constants .Shepherd .THEME_SQ_CSS
967
977
sh_theme_sq_dark_css = constants .Shepherd .THEME_SQ_DK_CSS
968
978
tether_js = constants .Tether .MIN_JS
969
- underscore_js = constants .Underscore .MIN_JS
970
- backbone_js = constants .Backbone .MIN_JS
971
979
spinner_css = constants .Messenger .SPINNER_CSS
972
980
973
981
sh_style = style_sheet .sh_style_test
@@ -987,8 +995,6 @@ def __activate_shepherd(self):
987
995
self .add_css_link (sh_theme_sq_css )
988
996
self .add_css_link (sh_theme_sq_dark_css )
989
997
self .add_js_link (tether_js )
990
- self .add_js_link (underscore_js )
991
- self .add_js_link (backbone_js )
992
998
self .add_js_link (shepherd_js )
993
999
time .sleep (0.1 )
994
1000
@@ -1085,7 +1091,7 @@ def create_shepherd_tour(self, name=None, theme=None):
1085
1091
new_tour = (
1086
1092
"""
1087
1093
// Shepherd Tour
1088
- let tour = new Shepherd.Tour({
1094
+ var tour = new Shepherd.Tour({
1089
1095
defaults: {
1090
1096
classes: '%s',
1091
1097
scrollTo: true
@@ -1399,7 +1405,10 @@ def __play_shepherd_tour(self, name=None, interval=0):
1399
1405
instructions = ""
1400
1406
for tour_step in self ._tour_steps [name ]:
1401
1407
instructions += tour_step
1402
- instructions += "tour.start();"
1408
+ instructions += ("""
1409
+ // Start the tour
1410
+ tour.start();
1411
+ $tour = tour;""" )
1403
1412
1404
1413
autoplay = False
1405
1414
if interval and interval > 0 :
@@ -1524,8 +1533,11 @@ def __play_bootstrap_tour(self, name=None, interval=0):
1524
1533
// Start the tour
1525
1534
tour.start();
1526
1535
1527
- $tour = tour;
1528
- $tour.restart();""" )
1536
+ // Fix timing issue by restarting tour immediately
1537
+ tour.restart();
1538
+
1539
+ // Save for later
1540
+ $tour = tour;""" )
1529
1541
1530
1542
if interval and interval > 0 :
1531
1543
if interval < 1 :
@@ -1727,8 +1739,9 @@ def __play_introjs_tour(self, name=None, interval=0):
1727
1739
intro.setOption("showStepNumbers", false);
1728
1740
intro.setOption("showProgress", false);
1729
1741
intro.start();
1730
- $intro = intro;
1731
- }
1742
+ $tour = intro;
1743
+ };
1744
+ // Start the tour
1732
1745
startIntro();
1733
1746
""" )
1734
1747
@@ -1774,7 +1787,7 @@ def __play_introjs_tour(self, name=None, interval=0):
1774
1787
time .sleep (0.01 )
1775
1788
if self .browser != "firefox" :
1776
1789
result = self .execute_script (
1777
- "return $intro ._currentStep" )
1790
+ "return $tour ._currentStep" )
1778
1791
else :
1779
1792
self .wait_for_element_present (
1780
1793
".introjs-tooltip" , timeout = 0.4 )
@@ -1787,7 +1800,7 @@ def __play_introjs_tour(self, name=None, interval=0):
1787
1800
if autoplay :
1788
1801
try :
1789
1802
current_step = self .execute_script (
1790
- "return $intro ._currentStep" )
1803
+ "return $tour ._currentStep" )
1791
1804
except Exception :
1792
1805
continue
1793
1806
if current_step != latest_step :
@@ -1797,10 +1810,10 @@ def __play_introjs_tour(self, name=None, interval=0):
1797
1810
now_ms = time .time () * 1000.0
1798
1811
if now_ms >= stop_ms :
1799
1812
if current_step == latest_step :
1800
- self .execute_script ("return $intro .nextStep()" )
1813
+ self .execute_script ("return $tour .nextStep()" )
1801
1814
try :
1802
1815
latest_step = self .execute_script (
1803
- "return $intro ._currentStep" )
1816
+ "return $tour ._currentStep" )
1804
1817
start_ms = time .time () * 1000.0
1805
1818
stop_ms = start_ms + (interval * 1000.0 )
1806
1819
except Exception :
@@ -1811,7 +1824,7 @@ def __play_introjs_tour(self, name=None, interval=0):
1811
1824
time .sleep (0.01 )
1812
1825
if self .browser != "firefox" :
1813
1826
result = self .execute_script (
1814
- "return $intro ._currentStep" )
1827
+ "return $tour ._currentStep" )
1815
1828
else :
1816
1829
self .wait_for_element_present (
1817
1830
".introjs-tooltip" , timeout = 0.4 )
0 commit comments