Improve setting up Sizzle for Selenium tests.

Something releated to AMD broke our way of injecting Sizzle into Galaxy for Selenium tests. This is a much better way that seems to work - just use jQuery ($) as Sizzle if it is available. Avoids an external dependency and another page fetch per test as well as fixing the problem.

Add a test case that just tests the sizzle stuff works on its own. It will be a clear indiciation what is broken if there are related regressions in the future.
This commit is contained in:
John Chilton
2017-08-30 14:07:55 -04:00
parent 43fd81df59
commit f35fed2935
2 changed files with 24 additions and 8 deletions
+14 -8
View File
@@ -95,12 +95,18 @@ def find_elements_by_sizzle(driver, sizzle_selector):
def _inject_sizzle(driver, sizzle_url, timeout):
script = """
var _s = document.createElement("script");
_s.type = "text/javascript";
_s.src = "{src}";
var _h = document.getElementsByTagName("head")[0];
_h.appendChild(_s);
""".format(src=sizzle_url)
if(typeof(window.$) != "undefined") {
// Just reuse jQuery if it is available, avoids potential amd problems
// that have cropped up with Galaxy for instance.
window.Sizzle = window.$;
} else {
var _s = document.createElement("script");
_s.type = "text/javascript";
_s.src = "%s";
var _h = document.getElementsByTagName("head")[0];
_h.appendChild(_s);
}
""" % sizzle_url
driver.execute_script(script)
wait = WebDriverWait(driver, timeout)
wait.until(lambda d: _is_sizzle_loaded(d),
@@ -121,8 +127,8 @@ def _make_sizzle_string(sizzle_selector):
__all__ = (
"sizzle_selector_clickable",
"sizzle_presence_of_selector",
"find_element_by_sizzle",
"find_elements_by_sizzle",
"sizzle_selector_clickable",
"sizzle_presence_of_selector",
)
@@ -0,0 +1,10 @@
from .framework import SeleniumTestCase
from .framework import selenium_test
class SizzleLoadingTestCase(SeleniumTestCase):
@selenium_test
def test_sizzle_loads(self):
self.home()
self.wait_for_sizzle_selector_clickable("div")