From bf84aca059ea71c0755ee5c60a1a4214c4b0a5e5 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 19 Jan 2017 11:44:10 -0500 Subject: [PATCH] Attempt work around for race-y sort of condition in Selenium sizzle checkers. I believe this rare condition explains this failing test here - https://jenkins.galaxyproject.org/view/All/job/selenium/54/testReport/junit/selenium_tests.test_stock_tours/TestStockToursTestCase/test_core_history/. This test has never failed for me locally and this is the only time I've seen it fail on Jenkins as well. --- test/galaxy_selenium/sizzle.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/galaxy_selenium/sizzle.py b/test/galaxy_selenium/sizzle.py index 517be77d4821..0ef2e84206a5 100644 --- a/test/galaxy_selenium/sizzle.py +++ b/test/galaxy_selenium/sizzle.py @@ -15,7 +15,21 @@ def ec(driver): if not elements: return False element = elements[0] - if element.is_displayed() and element.is_enabled(): + try: + clickable = element.is_displayed() and element.is_enabled() + except Exception as e: + # Handle the case where the element is detached between when it is + # discovered and when it is checked - it is likely changing quickly + # and the next pass will be the final state. If not, this should be + # wrapped in a wait anyway - so no problems there. For other + # non-custom selectors I believe this all happens on the Selenium + # server and so there is likely no need to handle this case - they + # are effectively atomic. + if _exception_indicates_stale_element(e): + return None + + raise + if clickable: return element else: return None @@ -29,7 +43,16 @@ def ec(driver): if not elements: return False element = elements[0] - if element.is_displayed(): + try: + displayed = element.is_displayed() + except Exception as e: + # See note above insizzle_selector_clickable about this exception. + if _exception_indicates_stale_element(e): + return None + + raise + + if displayed: return element else: return None @@ -37,6 +60,10 @@ def ec(driver): return ec +def _exception_indicates_stale_element(exception): + return "stale" in str(exception) + + def find_element_by_sizzle(driver, sizzle_selector): """ Finds an element by sizzle selector.