@@ -720,40 +720,46 @@ def maximize_window(self):
720720
721721 def add_css_link (self , css_link ):
722722 script_to_add_css = (
723- """function injectCSS() {
723+ """function injectCSS(css ) {
724724 var head = document.getElementsByTagName("head")[0];
725725 var link = document.createElement("link");
726726 link.rel = "stylesheet";
727727 link.type = "text/css";
728- link.href = "%s" ;
728+ link.href = css ;
729729 link.crossorigin = "anonymous";
730730 head.appendChild(link);
731731 }
732- injectCSS();""" )
732+ injectCSS("%s");""" )
733+ css_link = self .__escape_quotes_if_needed (css_link )
733734 self .execute_script (script_to_add_css % css_link )
734735
735736 def add_js_link (self , js_link ):
736737 script_to_add_js = (
737- """function injectJS() {
738+ """function injectJS(link ) {
738739 var head = document.getElementsByTagName("head")[0];
739740 var script = document.createElement("script");
740- script.src = "%s" ;
741+ script.src = link ;
741742 script.defer;
743+ script.type="text/javascript";
742744 script.crossorigin = "anonymous";
743745 script.onload = function() { null };
744746 head.appendChild(script);
745747 }
746- injectJS();""" )
748+ injectJS("%s");""" )
749+ js_link = self .__escape_quotes_if_needed (js_link )
747750 self .execute_script (script_to_add_js % js_link )
748751
749752 def add_css_style (self , css_style ):
750753 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 ' , '' )
757763 css_style = self .__escape_quotes_if_needed (css_style )
758764 self .execute_script (add_css_style_script % css_style )
759765
@@ -800,7 +806,11 @@ def activate_jquery(self):
800806 # jQuery is not currently defined. Let's proceed by defining it.
801807 pass
802808 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 )
804814 for x in range (int (settings .MINI_TIMEOUT * 10.0 )):
805815 # jQuery needs a small amount of time to activate.
806816 try :
@@ -966,8 +976,6 @@ def __activate_shepherd(self):
966976 sh_theme_sq_css = constants .Shepherd .THEME_SQ_CSS
967977 sh_theme_sq_dark_css = constants .Shepherd .THEME_SQ_DK_CSS
968978 tether_js = constants .Tether .MIN_JS
969- underscore_js = constants .Underscore .MIN_JS
970- backbone_js = constants .Backbone .MIN_JS
971979 spinner_css = constants .Messenger .SPINNER_CSS
972980
973981 sh_style = style_sheet .sh_style_test
@@ -987,8 +995,6 @@ def __activate_shepherd(self):
987995 self .add_css_link (sh_theme_sq_css )
988996 self .add_css_link (sh_theme_sq_dark_css )
989997 self .add_js_link (tether_js )
990- self .add_js_link (underscore_js )
991- self .add_js_link (backbone_js )
992998 self .add_js_link (shepherd_js )
993999 time .sleep (0.1 )
9941000
@@ -1085,7 +1091,7 @@ def create_shepherd_tour(self, name=None, theme=None):
10851091 new_tour = (
10861092 """
10871093 // Shepherd Tour
1088- let tour = new Shepherd.Tour({
1094+ var tour = new Shepherd.Tour({
10891095 defaults: {
10901096 classes: '%s',
10911097 scrollTo: true
@@ -1399,7 +1405,10 @@ def __play_shepherd_tour(self, name=None, interval=0):
13991405 instructions = ""
14001406 for tour_step in self ._tour_steps [name ]:
14011407 instructions += tour_step
1402- instructions += "tour.start();"
1408+ instructions += ("""
1409+ // Start the tour
1410+ tour.start();
1411+ $tour = tour;""" )
14031412
14041413 autoplay = False
14051414 if interval and interval > 0 :
@@ -1524,8 +1533,11 @@ def __play_bootstrap_tour(self, name=None, interval=0):
15241533 // Start the tour
15251534 tour.start();
15261535
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;""" )
15291541
15301542 if interval and interval > 0 :
15311543 if interval < 1 :
@@ -1727,8 +1739,9 @@ def __play_introjs_tour(self, name=None, interval=0):
17271739 intro.setOption("showStepNumbers", false);
17281740 intro.setOption("showProgress", false);
17291741 intro.start();
1730- $intro = intro;
1731- }
1742+ $tour = intro;
1743+ };
1744+ // Start the tour
17321745 startIntro();
17331746 """ )
17341747
@@ -1774,7 +1787,7 @@ def __play_introjs_tour(self, name=None, interval=0):
17741787 time .sleep (0.01 )
17751788 if self .browser != "firefox" :
17761789 result = self .execute_script (
1777- "return $intro ._currentStep" )
1790+ "return $tour ._currentStep" )
17781791 else :
17791792 self .wait_for_element_present (
17801793 ".introjs-tooltip" , timeout = 0.4 )
@@ -1787,7 +1800,7 @@ def __play_introjs_tour(self, name=None, interval=0):
17871800 if autoplay :
17881801 try :
17891802 current_step = self .execute_script (
1790- "return $intro ._currentStep" )
1803+ "return $tour ._currentStep" )
17911804 except Exception :
17921805 continue
17931806 if current_step != latest_step :
@@ -1797,10 +1810,10 @@ def __play_introjs_tour(self, name=None, interval=0):
17971810 now_ms = time .time () * 1000.0
17981811 if now_ms >= stop_ms :
17991812 if current_step == latest_step :
1800- self .execute_script ("return $intro .nextStep()" )
1813+ self .execute_script ("return $tour .nextStep()" )
18011814 try :
18021815 latest_step = self .execute_script (
1803- "return $intro ._currentStep" )
1816+ "return $tour ._currentStep" )
18041817 start_ms = time .time () * 1000.0
18051818 stop_ms = start_ms + (interval * 1000.0 )
18061819 except Exception :
@@ -1811,7 +1824,7 @@ def __play_introjs_tour(self, name=None, interval=0):
18111824 time .sleep (0.01 )
18121825 if self .browser != "firefox" :
18131826 result = self .execute_script (
1814- "return $intro ._currentStep" )
1827+ "return $tour ._currentStep" )
18151828 else :
18161829 self .wait_for_element_present (
18171830 ".introjs-tooltip" , timeout = 0.4 )
0 commit comments