Skip to content

Commit

Permalink
Improve setting up Sizzle for Selenium tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmchilton committed Aug 30, 2017
1 parent 43fd81d commit f35fed2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/galaxy_selenium/sizzle.py
Expand Up @@ -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),
Expand All @@ -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",
)
10 changes: 10 additions & 0 deletions test/selenium_tests/test_sizzle_loading.py
@@ -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")

0 comments on commit f35fed2

Please sign in to comment.