Skip to content

Save the URL with exported SeleniumBase tours #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ self.add_tour_step(message, selector=None, name=None,

self.play_tour(name=None)

self.export_tour(name=None, filename="my_tour.js")
self.export_tour(name=None, filename="my_tour.js", url=None)

self.activate_jquery_confirm()

Expand Down
22 changes: 12 additions & 10 deletions seleniumbase/core/tour_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def play_introjs_tour(
time.sleep(0.1)


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

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

instructions = (
'''//////// Load Tour Start Page (if not there now) ////////\n\n'''
'''if (window.location.href != "%s") {\n'''
''' window.location.href="%s";\n'''
'''}\n\n'''
'''//////// Resources ////////\n\n'''
'''function injectCSS(css_link) {'''
'''var head = document.getElementsByTagName("head")[0];'''
Expand All @@ -682,7 +688,7 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
'''style.type = "text/css";'''
'''style.appendChild(document.createTextNode(css));'''
'''head.appendChild(style);'''
'''};\n''')
'''};\n''' % (url, url))

if tour_type == "bootstrap":
jquery_js = constants.JQuery.MIN_JS
Expand Down Expand Up @@ -752,16 +758,14 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
// Start the tour
tour.start();
$tour = tour;
$tour.restart();\n
""")
$tour.restart();\n""")
elif tour_type == "hopscotch":
instructions += (
"""]
};
// Start the tour!
hopscotch.startTour(tour);
$tour = hopscotch;\n
""")
$tour = hopscotch;\n""")
elif tour_type == "introjs":
instructions += (
"""]
Expand All @@ -777,14 +781,12 @@ def export_tour(tour_steps, name=None, filename="my_tour.js"):
intro.start();
$tour = intro;
};
startIntro();\n
""")
startIntro();\n""")
elif tour_type == "shepherd":
instructions += (
"""
tour.start();
$tour = tour;\n
""")
$tour = tour;\n""")
else:
pass

Expand Down
11 changes: 7 additions & 4 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,10 @@ def play_tour(self, name=None, interval=0):
self.driver, self._tour_steps,
self.message_duration, name=name, interval=interval)

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

def activate_jquery_confirm(self):
""" See https://craftpip.github.io/jquery-confirm/ for usage. """
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='seleniumbase',
version='1.19.1',
version='1.19.2',
description='Easy, Fast, Reliable Browser Automation & Testing Framework',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down