Skip to content
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ script:
- "nosetests examples/boilerplates/boilerplate_test.py --browser=chrome --headless"
- "pytest examples/my_first_test.py --browser=firefox -s --headless --with-db_reporting"
- "pytest examples/my_first_test.py --browser=chrome -s --headless --with-db_reporting --demo_mode --demo_sleep=0.2"
- "pytest examples/tour_examples/google_tour.py -s --headless --with-db_reporting"
- "sudo mysql --password=test -e 'select test_address,browser,state,start_time,runtime from test_db.test_run_data'"
after_script:
- "sudo mysql -e 'DROP DATABASE test_db;'"
Expand Down
5 changes: 2 additions & 3 deletions examples/proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ class MyTestClass(BaseCase):

def test_proxy(self):
self.open('https://ipinfo.io/')
ip_address = self.get_page_title().split(' ')[0]
ip_address = self.get_text("div.home-ip-details span.value")[1:-1]
self.open('https://ipinfo.io/%s' % ip_address)
print("\n\nIP Address = %s\n" % ip_address)
href = '/%s' % ip_address
self.click('[href="%s"]' % href)
print("Displaying Host Info:")
print(self.get_text('table.table'))
print("\nThe browser will close automatically in 7 seconds...")
Expand Down
8 changes: 4 additions & 4 deletions examples/tour_examples/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

![](https://cdn2.hubspot.net/hubfs/100006/images/google_tour.gif "SeleniumBase Tours")<br>

SeleniumBase Tours utilize the [HubSpot Shepherd Library](http://github.hubspot.com/shepherd/docs/welcome/) for creating and running tours on any website.
SeleniumBase Tours utilize the [HubSpot Shepherd Library](http://github.hubspot.com/shepherd/docs/welcome/) for creating and running tours, demos, and walkthroughs on any website.

To utilize tours, there are three methods that you need to know at the basic level (which contain optional arguments):

``self.create_tour(theme)``

``self.add_tour_step(message, css_selector, title, alignment, theme)``

``self.play_tour()``
``self.play_tour(interval)``

With the ``create_tour()`` method, you can pass a default theme to change the look & feel of the tour steps. Valid themes are ``dark``, ``default``, ``arrows``, ``square``, and ``square-dark``.

With the ``self.add_tour_step()`` method, at minimum you must pass a message to display. Then you can specify a web element to attach to (by CSS selector). If no element is specified, the tour step will tether to the top of the screen by default. You can add an optional title above the message to display with the tour step. You can also change the theme for that step, as well as specifiy the alignment (which is the side of the element that you want the tour message to tether to).
With the ``self.add_tour_step()`` method, at minimum you must pass a message to display. Then you can specify a web element to attach to (by CSS selector). If no element is specified, the tour step will tether to the top of the screen by default. You can also add an optional title above the message to display with the tour step, as well as change the theme for that step, and even specify the alignment (which is the side of the element that you want the tour message to tether to).

Finally, you can play a tour you created by calling the ``self.play_tour()`` method.
Finally, you can play a tour you created by calling the ``self.play_tour()`` method. If you specify an interval, the tour will automatically walk through each step after that many seconds have passed.

### Here's an example of using SeleniumBase Tours:

Expand Down
73 changes: 55 additions & 18 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,15 +1030,24 @@ def add_tour_step(self, message, selector=None, name=None,

self._tour_steps[name].append(step)

def play_tour(self, name=None):
def play_tour(self, name=None, interval=0):
""" Plays a tour on the current website.
@Params
name - If creating multiple tours, use this to select the
tour you wish to play.
interval - The delay time between autoplaying tour steps.
If set to 0 (default), the tour is fully manual control.
"""
if self.headless:
return # Tours should not run in headless mode.

autoplay = False
if interval and interval > 0:
autoplay = True
interval = float(interval)
if interval < 0.5:
interval = 0.5

if not name:
name = "default"
if name not in self._tour_steps:
Expand Down Expand Up @@ -1070,6 +1079,11 @@ def play_tour(self, name=None):

self.execute_script(instructions)
tour_on = True
if autoplay:
start_ms = time.time() * 1000.0
stop_ms = start_ms + (interval * 1000.0)
latest_element = None
latest_text = None
while tour_on:
try:
time.sleep(0.01)
Expand All @@ -1080,6 +1094,33 @@ def play_tour(self, name=None):
result = None
if result:
tour_on = True
if autoplay:
try:
element = self.execute_script(
"Shepherd.activeTour.currentStep"
".options.attachTo.element")
shep_text = self.execute_script(
"Shepherd.activeTour.currentStep.options.text")
except Exception:
continue
now_ms = time.time() * 1000.0
if now_ms >= stop_ms:
if ((element == latest_element) and
(shep_text == latest_text)):
self.execute_script("Shepherd.activeTour.next()")
try:
latest_element = self.execute_script(
"Shepherd.activeTour.currentStep"
".options.attachTo.element")
latest_text = self.execute_script(
"Shepherd.activeTour.currentStep"
".options.text")
start_ms = time.time() * 1000.0
stop_ms = start_ms + (interval * 1000.0)
except Exception:
pass
continue

else:
try:
time.sleep(0.01)
Expand All @@ -1097,6 +1138,9 @@ def play_tour(self, name=None):
duration=settings.SMALL_TIMEOUT)
time.sleep(0.1)
self.execute_script("Shepherd.activeTour.next()")
if autoplay:
start_ms = time.time() * 1000.0
stop_ms = start_ms + (interval * 1000.0)
tour_on = True
except Exception:
tour_on = False
Expand Down Expand Up @@ -1134,12 +1178,6 @@ def activate_messenger(self):
"/messenger/1.5.0/js/messenger-theme-flat.js")
msg_theme_future_js = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/js/messenger-theme-future.js")
msgr_theme_block_js = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/js/messenger-theme-block.js")
msgr_theme_air_js = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/js/messenger-theme-air.js")
msgr_theme_ice_js = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/js/messenger-theme-ice.js")
underscore_js = ("https://cdnjs.cloudflare.com/ajax/libs"
"/underscore.js/1.4.3/underscore-min.js")
backbone_js = ("https://cdnjs.cloudflare.com/ajax/libs"
Expand All @@ -1150,9 +1188,9 @@ def activate_messenger(self):
"/messenger/1.5.0/css/messenger.css")
msgr_theme_flat_css = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/css/messenger-theme-flat.css")
msgr_theme_futur_css = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/css/"
"messenger-theme-future.css")
msgr_theme_future_css = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/css/"
"messenger-theme-future.css")
msgr_theme_block_css = ("https://cdnjs.cloudflare.com/ajax/libs"
"/messenger/1.5.0/css/"
"messenger-theme-block.css")
Expand All @@ -1169,7 +1207,7 @@ def activate_messenger(self):
self.add_js_link(jquery_js)
self.add_css_link(messenger_css)
self.add_css_link(msgr_theme_flat_css)
self.add_css_link(msgr_theme_futur_css)
self.add_css_link(msgr_theme_future_css)
self.add_css_link(msgr_theme_block_css)
self.add_css_link(msgr_theme_air_css)
self.add_css_link(msgr_theme_ice_css)
Expand All @@ -1179,9 +1217,6 @@ def activate_messenger(self):
self.add_js_link(messenger_js)
self.add_js_link(msgr_theme_flat_js)
self.add_js_link(msg_theme_future_js)
self.add_js_link(msgr_theme_block_js)
self.add_js_link(msgr_theme_air_js)
self.add_js_link(msgr_theme_ice_js)

for x in range(int(settings.MINI_TIMEOUT * 10.0)):
# Messenger needs a small amount of time to load & activate.
Expand Down Expand Up @@ -1320,13 +1355,15 @@ def bring_to_front(self, selector, by=By.CSS_SELECTOR):
self.execute_script(script)

def highlight_click(self, selector, by=By.CSS_SELECTOR,
loops=2, scroll=True):
self.highlight(selector, by=by, loops=loops, scroll=scroll)
loops=3, scroll=True):
if not self.demo_mode:
self.highlight(selector, by=by, loops=loops, scroll=scroll)
self.click(selector, by=by)

def highlight_update_text(self, selector, new_value, by=By.CSS_SELECTOR,
loops=2, scroll=True):
self.highlight(selector, by=by, loops=loops, scroll=scroll)
loops=3, scroll=True):
if not self.demo_mode:
self.highlight(selector, by=by, loops=loops, scroll=scroll)
self.update_text(selector, new_value, by=by)

def highlight(self, selector, by=By.CSS_SELECTOR,
Expand Down
Loading