Skip to content

Commit 87966aa

Browse files
authored
Merge pull request #187 from seleniumbase/refactoring-and-tour-updates
Refactoring and tour updates
2 parents 18688ee + 2d36327 commit 87966aa

File tree

5 files changed

+75
-64
lines changed

5 files changed

+75
-64
lines changed

examples/boilerplates/samples/google_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_google_dot_com(self):
1212
self.open('https://google.com')
1313
try:
1414
# Remove the Privacy Checkup box if present.
15-
self.assert_text('Privacy Checkup', HomePage.dialog_box, timeout=3)
15+
self.assert_text('Privacy Checkup', HomePage.dialog_box, timeout=2)
1616
self.click('link=NO, THANKS')
1717
except Exception:
1818
pass # Google may have removed the Privacy Checkup. Continue test.

examples/tour_examples/google_tour.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,36 @@ class MyTourClass(BaseCase):
66
def test_google_tour(self):
77
self.open('https://google.com')
88
self.wait_for_element('input[title="Search"]')
9+
try:
10+
# Remove the Privacy Checkup box if present.
11+
self.assert_text('Privacy Checkup', '[role="dialog"]', timeout=2)
12+
self.click('link=NO, THANKS')
13+
except Exception:
14+
pass # Google may have removed the Privacy Checkup. Continue.
915
self.create_tour(theme="dark")
1016
self.add_tour_step("Click to begin the Google Tour!",
1117
title="SeleniumBase Guided Tours")
1218
self.add_tour_step("Type in your search query here.",
1319
'input[title="Search"]')
14-
self.add_tour_step("Then click here to search!",
15-
'input[value="Google Search"]',
16-
alignment="bottom", theme="arrows")
17-
self.add_tour_step("Or click here to see the top result.",
18-
'''[value="I'm Feeling Lucky"]''',
19-
alignment="bottom", theme="arrows")
20+
self.add_tour_step(
21+
"Then click here to search!", 'input[value="Google Search"]',
22+
alignment="bottom", theme="arrows")
23+
self.add_tour_step(
24+
"Or click here to see the top result.",
25+
'''[value="I'm Feeling Lucky"]''',
26+
alignment="bottom", theme="arrows")
2027
self.add_tour_step("Here's an example Google search...",
2128
theme="arrows")
22-
self.play_tour()
29+
self.play_tour(interval=0) # If interval is 0, tour is fully manual
2330

2431
self.highlight_update_text('input[title="Search"]', "GitHub")
2532
self.highlight_click('input[value="Google Search"]')
2633
self.create_tour(theme="dark")
27-
self.add_tour_step("Voila! Search results appear here!")
34+
self.add_tour_step("Search results appear here!",
35+
title="(5-second autoplay on)")
2836
self.add_tour_step("Let's take another tour...",
2937
title="Ready for more?", theme="square")
30-
self.play_tour()
38+
self.play_tour(interval=5) # tour automatically continues after 3s
3139

3240
self.open("https://www.google.com/maps/@42.3598616,-71.0912631,15z")
3341
self.wait_for_element('input#searchboxinput')
@@ -53,4 +61,4 @@ def test_google_tour(self):
5361
'[title="Google apps"]', alignment="left")
5462
self.add_tour_step("Thanks for trying out SeleniumBase tours!",
5563
title="End of Guided Tour", theme="square")
56-
self.play_tour()
64+
self.play_tour() # If interval isn't set, tour is fully manual

seleniumbase/core/style_sheet.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,47 @@
9696
padding-left: 20px;
9797
}
9898
</style>'''
99+
100+
sh_style_test = (
101+
'''
102+
let test_tour = new Shepherd.Tour({
103+
defaults: {
104+
classes: 'shepherd-theme-dark',
105+
scrollTo: true
106+
}
107+
});
108+
''')
109+
110+
sh_backdrop_style = (
111+
'''
112+
body.shepherd-active .shepherd-target.shepherd-enabled {
113+
box-shadow: 0 0 0 99999px rgba(0, 0, 0, 0.22);
114+
pointer-events: none !important;
115+
z-index: 9999;
116+
}
117+
118+
body.shepherd-active .shepherd-orphan {
119+
box-shadow: 0 0 0 99999px rgba(0, 0, 0, 0.16);
120+
pointer-events: auto;
121+
z-index: 9999;
122+
}
123+
124+
body.shepherd-active
125+
.shepherd-enabled.shepherd-element-attached-top {
126+
position: relative;
127+
}
128+
129+
body.shepherd-active
130+
.shepherd-enabled.shepherd-element-attached-bottom {
131+
position: relative;
132+
}
133+
134+
body.shepherd-active .shepherd-step {
135+
pointer-events: auto;
136+
z-index: 9999;
137+
}
138+
139+
body.shepherd-active {
140+
pointer-events: none !important;
141+
}
142+
''')

seleniumbase/fixtures/base_case.py

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_anything(self):
4242
from seleniumbase.core.testcase_manager import TestcaseManager
4343
from seleniumbase.core import download_helper
4444
from seleniumbase.core import log_helper
45+
from seleniumbase.core import style_sheet
4546
from seleniumbase.fixtures import constants
4647
from seleniumbase.fixtures import page_actions
4748
from seleniumbase.fixtures import page_utils
@@ -732,7 +733,7 @@ def add_js_link(self, js_link):
732733
script.src = "%s";
733734
script.defer;
734735
script.crossorigin = "anonymous";
735-
script.onload = function() {$("html")};
736+
script.onload = function() { null };
736737
head.appendChild(script);
737738
}
738739
injectJS();""")
@@ -755,7 +756,7 @@ def add_js_code_from_link(self, js_link):
755756
'''var h = document.getElementsByTagName('head').item(0);'''
756757
'''var s = document.createElement("script");'''
757758
'''s.type = "text/javascript";'''
758-
'''s.onload = function() {$("html")};'''
759+
'''s.onload = function() { null };'''
759760
'''s.appendChild(document.createTextNode("%s"));'''
760761
'''h.appendChild(s);''')
761762
self.execute_script(add_js_code_script % re.escape(js_code))
@@ -860,46 +861,8 @@ def __activate_shepherd(self):
860861
backbone_js = constants.Backbone.MIN_JS
861862
spinner_css = constants.Messenger.SPINNER_CSS
862863

863-
backdrop_style = (
864-
'''
865-
body.shepherd-active .shepherd-target.shepherd-enabled {
866-
box-shadow: 0 0 0 99999px rgba(0, 0, 0, 0.22);
867-
pointer-events: none !important;
868-
z-index: 9999;
869-
}
870-
871-
body.shepherd-active .shepherd-orphan {
872-
box-shadow: 0 0 0 99999px rgba(0, 0, 0, 0.16);
873-
pointer-events: auto;
874-
z-index: 9999;
875-
}
876-
877-
body.shepherd-active
878-
.shepherd-enabled.shepherd-element-attached-top {
879-
position: relative;
880-
}
881-
882-
body.shepherd-active
883-
.shepherd-enabled.shepherd-element-attached-bottom {
884-
position: relative;
885-
}
886-
887-
body.shepherd-active .shepherd-step {
888-
pointer-events: auto;
889-
z-index: 9999;
890-
}
891-
892-
body.shepherd-active {
893-
pointer-events: none !important;
894-
}
895-
''')
896-
897-
sh_style = ("""let test_tour = new Shepherd.Tour({
898-
defaults: {
899-
classes: 'shepherd-theme-dark',
900-
scrollTo: true
901-
}
902-
});""")
864+
sh_style = style_sheet.sh_style_test
865+
backdrop_style = style_sheet.sh_backdrop_style
903866

904867
self.__activate_bootstrap()
905868
for x in range(4):
@@ -922,7 +885,7 @@ def __activate_shepherd(self):
922885
for x in range(int(settings.MINI_TIMEOUT * 2.0)):
923886
# Shepherd needs a small amount of time to load & activate.
924887
try:
925-
self.execute_script(sh_style)
888+
self.execute_script(sh_style) # Verify Shepherd has loaded
926889
self.wait_for_ready_state_complete()
927890
self.execute_script(sh_style) # Need it twice for ordering
928891
time.sleep(0.05)
@@ -936,14 +899,9 @@ def __activate_shepherd(self):
936899
'''directive. ''' % self.driver.current_url)
937900

938901
def __is_shepherd_activated(self):
939-
sh_style = ("""let test_tour = new Shepherd.Tour({
940-
defaults: {
941-
classes: 'shepherd-theme-dark',
942-
scrollTo: true
943-
}
944-
});""")
902+
sh_style = style_sheet.sh_style_test
945903
try:
946-
self.execute_script(sh_style)
904+
self.execute_script(sh_style) # Verify Shepherd has loaded
947905
return True
948906
except Exception:
949907
return False
@@ -1086,7 +1044,8 @@ def play_tour(self, name=None, interval=0):
10861044
selector = re.search(
10871045
"[\S\s]+{element: '([\S\s]+)', on: [\S\s]+",
10881046
self._tour_steps[name][1]).group(1)
1089-
self.__wait_for_css_query_selector(selector)
1047+
self.__wait_for_css_query_selector(
1048+
selector, timeout=(settings.SMALL_TIMEOUT))
10901049
except Exception:
10911050
self.__post_messenger_error_message(
10921051
"Tour Error: {'%s'} was not found!"
@@ -1149,7 +1108,7 @@ def play_tour(self, name=None, interval=0):
11491108
".currentStep.options.attachTo.element")
11501109
try:
11511110
self.__wait_for_css_query_selector(
1152-
selector, timeout=(settings.MINI_TIMEOUT * 2))
1111+
selector, timeout=(settings.MINI_TIMEOUT))
11531112
except Exception:
11541113
self.remove_elements("div.shepherd-content")
11551114
self.__post_messenger_error_message(

setup.py

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

88
setup(
99
name='seleniumbase',
10-
version='1.13.6',
10+
version='1.13.7',
1111
description='Web Automation & Testing Framework - http://seleniumbase.com',
1212
long_description='Web Automation and Testing Framework - seleniumbase.com',
1313
platforms='Mac * Windows * Linux * Docker',

0 commit comments

Comments
 (0)