Skip to content

Commit 5e2a54f

Browse files
committed
Refactor jQuery exception code
1 parent 43ae2b8 commit 5e2a54f

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

seleniumbase/core/tour_helper.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
EXPORTED_TOURS_FOLDER = "tours_exported"
1616

1717

18-
def raise_unable_to_load_jquery_exception(driver):
19-
""" The most-likely reason for jQuery not loading on web pages. """
20-
raise Exception(
21-
'''Unable to load jQuery on "%s" due to a possible violation '''
22-
'''of the website's Content Security Policy '''
23-
'''directive. ''' % driver.current_url)
24-
25-
2618
def activate_bootstrap(driver):
2719
""" Allows you to use Bootstrap Tours with SeleniumBase
2820
http://bootstraptour.com/
@@ -51,7 +43,7 @@ def activate_bootstrap(driver):
5143
return
5244
except Exception:
5345
time.sleep(0.15)
54-
raise_unable_to_load_jquery_exception(driver)
46+
js_utils.raise_unable_to_load_jquery_exception(driver)
5547

5648

5749
def is_bootstrap_activated(driver):
@@ -96,7 +88,7 @@ def activate_hopscotch(driver):
9688
return
9789
except Exception:
9890
time.sleep(0.15)
99-
raise_unable_to_load_jquery_exception(driver)
91+
js_utils.raise_unable_to_load_jquery_exception(driver)
10092

10193

10294
def is_hopscotch_activated(driver):
@@ -139,7 +131,7 @@ def activate_introjs(driver):
139131
return
140132
except Exception:
141133
time.sleep(0.15)
142-
raise_unable_to_load_jquery_exception(driver)
134+
js_utils.raise_unable_to_load_jquery_exception(driver)
143135

144136

145137
def is_introjs_activated(driver):
@@ -199,7 +191,7 @@ def activate_shepherd(driver):
199191
return
200192
except Exception:
201193
time.sleep(0.15)
202-
raise_unable_to_load_jquery_exception(driver)
194+
js_utils.raise_unable_to_load_jquery_exception(driver)
203195

204196

205197
def is_shepherd_activated(driver):

seleniumbase/fixtures/js_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ def wait_for_jquery_active(driver, timeout=None):
107107
time.sleep(0.1)
108108

109109

110+
def raise_unable_to_load_jquery_exception(driver):
111+
""" The most-likely reason for jQuery not loading on web pages. """
112+
raise Exception(
113+
'''Unable to load jQuery on "%s" due to a possible violation '''
114+
'''of the website's Content Security Policy directive. '''
115+
'''To override this policy, add "--disable-csp" on the '''
116+
'''command-line when running your tests.''' % driver.current_url)
117+
118+
110119
def activate_jquery(driver):
111120
""" If "jQuery is not defined", use this method to activate it for use.
112121
This happens because jQuery is not always defined on web sites. """
@@ -132,11 +141,7 @@ def activate_jquery(driver):
132141
except Exception:
133142
time.sleep(0.1)
134143
# Since jQuery still isn't activating, give up and raise an exception
135-
raise Exception(
136-
'''Unable to load jQuery on "%s" due to a possible violation '''
137-
'''of the website's Content Security Policy directive. '''
138-
'''To override this policy, add "--disable_csp" on the '''
139-
'''command-line when running your tests.''' % driver.current_url)
144+
raise_unable_to_load_jquery_exception(driver)
140145

141146

142147
def are_quotes_escaped(string):

0 commit comments

Comments
 (0)