Skip to content

Commit 2cbeb72

Browse files
authored
Merge pull request #274 from seleniumbase/tour-update
Save the URL with exported SeleniumBase tours
2 parents be65fb0 + 51f4a48 commit 2cbeb72

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

help_docs/method_summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ self.add_tour_step(message, selector=None, name=None,
114114

115115
self.play_tour(name=None)
116116

117-
self.export_tour(name=None, filename="my_tour.js")
117+
self.export_tour(name=None, filename="my_tour.js", url=None)
118118

119119
self.activate_jquery_confirm()
120120

seleniumbase/core/tour_helper.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def play_introjs_tour(
631631
time.sleep(0.1)
632632

633633

634-
def export_tour(tour_steps, name=None, filename="my_tour.js"):
634+
def export_tour(tour_steps, name=None, filename="my_tour.js", url=None):
635635
""" Exports a tour as a JS file.
636636
It will include necessary resources as well, such as jQuery.
637637
You'll be able to copy the tour directly into the Console of
@@ -642,6 +642,8 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
642642
raise Exception("Tour {%s} does not exist!" % name)
643643
if not filename.endswith('.js'):
644644
raise Exception('Tour file must end in ".js"!')
645+
if not url:
646+
url = "data:,"
645647

646648
tour_type = None
647649
if "Bootstrap" in tour_steps[name][0]:
@@ -656,6 +658,10 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
656658
raise Exception('Unknown tour type!')
657659

658660
instructions = (
661+
'''//////// Load Tour Start Page (if not there now) ////////\n\n'''
662+
'''if (window.location.href != "%s") {\n'''
663+
''' window.location.href="%s";\n'''
664+
'''}\n\n'''
659665
'''//////// Resources ////////\n\n'''
660666
'''function injectCSS(css_link) {'''
661667
'''var head = document.getElementsByTagName("head")[0];'''
@@ -682,7 +688,7 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
682688
'''style.type = "text/css";'''
683689
'''style.appendChild(document.createTextNode(css));'''
684690
'''head.appendChild(style);'''
685-
'''};\n''')
691+
'''};\n''' % (url, url))
686692

687693
if tour_type == "bootstrap":
688694
jquery_js = constants.JQuery.MIN_JS
@@ -752,16 +758,14 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
752758
// Start the tour
753759
tour.start();
754760
$tour = tour;
755-
$tour.restart();\n
756-
""")
761+
$tour.restart();\n""")
757762
elif tour_type == "hopscotch":
758763
instructions += (
759764
"""]
760765
};
761766
// Start the tour!
762767
hopscotch.startTour(tour);
763-
$tour = hopscotch;\n
764-
""")
768+
$tour = hopscotch;\n""")
765769
elif tour_type == "introjs":
766770
instructions += (
767771
"""]
@@ -777,14 +781,12 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
777781
intro.start();
778782
$tour = intro;
779783
};
780-
startIntro();\n
781-
""")
784+
startIntro();\n""")
782785
elif tour_type == "shepherd":
783786
instructions += (
784787
"""
785788
tour.start();
786-
$tour = tour;\n
787-
""")
789+
$tour = tour;\n""")
788790
else:
789791
pass
790792

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,10 +1181,10 @@ def play_tour(self, name=None, interval=0):
11811181
self.driver, self._tour_steps,
11821182
self.message_duration, name=name, interval=interval)
11831183

1184-
def export_tour(self, name=None, filename="my_tour.js"):
1184+
def export_tour(self, name=None, filename="my_tour.js", url=None):
11851185
""" Exports a tour as a JS file.
1186-
You can call self.export_tour() anywhere where you could
1187-
normally use self.play_tour()
1186+
You can call self.export_tour() anywhere where you would
1187+
normally use self.play_tour() to play a tour.
11881188
It will include necessary resources as well, such as jQuery.
11891189
You'll be able to copy the tour directly into the Console of
11901190
any web browser to play the tour outside of SeleniumBase runs.
@@ -1193,7 +1193,10 @@ def export_tour(self, name=None, filename="my_tour.js"):
11931193
use this to select the tour you wish to add steps to.
11941194
filename - The name of the JavaScript file that you wish to
11951195
save the tour to. """
1196-
tour_helper.export_tour(self._tour_steps, name=name, filename=filename)
1196+
if not url:
1197+
url = self.get_current_url()
1198+
tour_helper.export_tour(
1199+
self._tour_steps, name=name, filename=filename, url=url)
11971200

11981201
def activate_jquery_confirm(self):
11991202
""" See https://craftpip.github.io/jquery-confirm/ for usage. """

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.19.1',
20+
version='1.19.2',
2121
description='Easy, Fast, Reliable Browser Automation & Testing Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)