Skip to content

Commit 48c915e

Browse files
committed
Improve the Python APIs for IntroJS website tours
1 parent a244324 commit 48c915e

File tree

5 files changed

+108
-11
lines changed

5 files changed

+108
-11
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ self.create_hopscotch_tour(name=None)
507507

508508
self.create_introjs_tour(name=None)
509509

510+
self.set_introjs_colors(theme_color=None, hover_color=None)
511+
510512
self.add_tour_step(message, selector=None, name=None,
511513
title=None, theme=None, alignment=None)
512514

seleniumbase/core/style_sheet.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
#driver-popover-item, .popover-class {
118118
pointer-events: auto !important;
119119
}
120+
button.driver-prev-btn.driver-disabled {
121+
visibility: hidden;
122+
}
120123
"""
121124

122125
messenger_style = """
@@ -146,6 +149,35 @@
146149
}
147150
"""
148151

152+
# IntroJS Style
153+
introjs_style = """
154+
.introjs-button.introjs-nextbutton,
155+
.introjs-button.introjs-donebutton {
156+
color: #fff !important;
157+
background-color: %s !important;
158+
border: 1px solid %s !important;
159+
text-shadow: none;
160+
box-shadow: none;
161+
}
162+
.introjs-button.introjs-nextbutton:hover,
163+
.introjs-button.introjs-donebutton:hover {
164+
color: #fff !important;
165+
background-color: %s !important;
166+
border: 1px solid %s !important;
167+
}
168+
.introjs-button {
169+
box-sizing: content-box;
170+
text-decoration: none;
171+
}
172+
.introjs-button.introjs-skipbutton {
173+
color: %s;
174+
}
175+
.introjs-tooltip, .introjs-floating {
176+
box-sizing: content-box;
177+
position: absolute;
178+
}
179+
"""
180+
149181
# Shepherd Backdrop Style
150182
sh_backdrop_style = """
151183
body.shepherd-active .shepherd-target.shepherd-enabled {

seleniumbase/core/tour_helper.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import time
88
from selenium.webdriver.common.by import By
9+
from seleniumbase import config as sb_config
910
from seleniumbase.config import settings
1011
from seleniumbase.core import style_sheet
1112
from seleniumbase.fixtures import constants
@@ -154,13 +155,24 @@ def activate_introjs(driver):
154155
intro_css = constants.IntroJS.MIN_CSS
155156
intro_js = constants.IntroJS.MIN_JS
156157

158+
theme_color = sb_config.introjs_theme_color
159+
hover_color = sb_config.introjs_hover_color
160+
backdrop_style = style_sheet.introjs_style % (
161+
theme_color,
162+
hover_color,
163+
hover_color,
164+
hover_color,
165+
theme_color,
166+
)
167+
157168
verify_script = """// Verify IntroJS activated
158169
var intro2 = introJs();
159170
"""
160171

161172
activate_bootstrap(driver)
162173
js_utils.wait_for_ready_state_complete(driver)
163174
js_utils.wait_for_angularjs(driver)
175+
js_utils.add_css_style(driver, backdrop_style)
164176
for x in range(4):
165177
js_utils.activate_jquery(driver)
166178
js_utils.add_css_link(driver, intro_css)
@@ -727,7 +739,9 @@ def play_introjs_tour(
727739
intro.setOption("overlayOpacity", .29);
728740
intro.setOption("scrollToElement", true);
729741
intro.setOption("keyboardNavigation", true);
730-
intro.setOption("exitOnEsc", false);
742+
intro.setOption("exitOnEsc", true);
743+
intro.setOption("hidePrev", true);
744+
intro.setOption("nextToDone", true);
731745
intro.setOption("exitOnOverlayClick", false);
732746
intro.setOption("showStepNumbers", false);
733747
intro.setOption("showProgress", false);
@@ -946,7 +960,19 @@ def export_tour(tour_steps, name=None, filename="my_tour.js", url=None):
946960
elif tour_type == "introjs":
947961
intro_css = constants.IntroJS.MIN_CSS
948962
intro_js = constants.IntroJS.MIN_JS
963+
theme_color = sb_config.introjs_theme_color
964+
hover_color = sb_config.introjs_hover_color
965+
backdrop_style = style_sheet.introjs_style % (
966+
theme_color,
967+
hover_color,
968+
hover_color,
969+
hover_color,
970+
theme_color,
971+
)
972+
backdrop_style = backdrop_style.replace("\n", "")
973+
backdrop_style = js_utils.escape_quotes_if_needed(backdrop_style)
949974
instructions += 'injectCSS("%s");\n' % intro_css
975+
instructions += 'injectStyle("%s");\n' % backdrop_style
950976
instructions += 'injectJS("%s");' % intro_js
951977

952978
elif tour_type == "shepherd":
@@ -1028,7 +1054,9 @@ def export_tour(tour_steps, name=None, filename="my_tour.js", url=None):
10281054
intro.setOption("overlayOpacity", .29);
10291055
intro.setOption("scrollToElement", true);
10301056
intro.setOption("keyboardNavigation", true);
1031-
intro.setOption("exitOnEsc", false);
1057+
intro.setOption("exitOnEsc", true);
1058+
intro.setOption("hidePrev", true);
1059+
intro.setOption("nextToDone", true);
10321060
intro.setOption("exitOnOverlayClick", false);
10331061
intro.setOption("showStepNumbers", false);
10341062
intro.setOption("showProgress", false);

seleniumbase/fixtures/base_case.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,6 +6228,10 @@ def create_introjs_tour(self, name=None):
62286228
name - If creating multiple tours at the same time,
62296229
use this to select the tour you wish to add steps to.
62306230
"""
6231+
if not hasattr(sb_config, "introjs_theme_color"):
6232+
sb_config.introjs_theme_color = constants.TourColor.theme_color
6233+
if not hasattr(sb_config, "introjs_hover_color"):
6234+
sb_config.introjs_hover_color = constants.TourColor.hover_color
62316235
if not name:
62326236
name = "default"
62336237

@@ -6242,6 +6246,36 @@ def create_introjs_tour(self, name=None):
62426246
self._tour_steps[name] = []
62436247
self._tour_steps[name].append(new_tour)
62446248

6249+
def set_introjs_colors(self, theme_color=None, hover_color=None):
6250+
"""Use this method to set the theme colors for IntroJS tours.
6251+
Args must be hex color values that start with a "#" sign.
6252+
If a color isn't specified, the color will reset to the default.
6253+
The border color of buttons is set to the hover color.
6254+
@Params
6255+
theme_color - The color of buttons.
6256+
hover_color - The color of buttons after hovering over them.
6257+
"""
6258+
if not hasattr(sb_config, "introjs_theme_color"):
6259+
sb_config.introjs_theme_color = constants.TourColor.theme_color
6260+
if not hasattr(sb_config, "introjs_hover_color"):
6261+
sb_config.introjs_hover_color = constants.TourColor.hover_color
6262+
if theme_color:
6263+
match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', theme_color)
6264+
if not match:
6265+
raise Exception(
6266+
'Expecting a hex value color that starts with "#"!')
6267+
sb_config.introjs_theme_color = theme_color
6268+
else:
6269+
sb_config.introjs_theme_color = constants.TourColor.theme_color
6270+
if hover_color:
6271+
match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', hover_color)
6272+
if not match:
6273+
raise Exception(
6274+
'Expecting a hex value color that starts with "#"!')
6275+
sb_config.introjs_hover_color = hover_color
6276+
else:
6277+
sb_config.introjs_hover_color = constants.TourColor.hover_color
6278+
62456279
def add_tour_step(
62466280
self,
62476281
message,

seleniumbase/fixtures/constants.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ class HighCharts:
232232
)
233233

234234

235+
class TourColor:
236+
# theme_color = "#f26721" # Orange
237+
# hover_color = "#db5409" # Darker Orange
238+
theme_color = "#2167e2" # Blue
239+
hover_color = "#0954cb" # Darker Blue
240+
241+
235242
class BootstrapTour:
236243
VER = "0.12.0"
237244
MIN_CSS = (
@@ -269,15 +276,9 @@ class Hopscotch:
269276

270277

271278
class IntroJS:
272-
VER = "2.9.3"
273-
MIN_CSS = (
274-
"https://cdnjs.cloudflare.com/ajax/libs/"
275-
"intro.js/%s/introjs.css" % VER
276-
)
277-
MIN_JS = (
278-
"https://cdnjs.cloudflare.com/ajax/libs/"
279-
"intro.js/%s/intro.min.js" % VER
280-
)
279+
VER = "4.2.2"
280+
MIN_CSS = "https://unpkg.com/intro.js@%s/minified/introjs.min.css" % VER
281+
MIN_JS = "https://unpkg.com/intro.js@%s/minified/intro.min.js" % VER
281282

282283

283284
class JqueryConfirm:

0 commit comments

Comments
 (0)