From 3d13a2bb4f75f2224f24511aa96c9f97d8ff3e44 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 21 Mar 2017 14:41:06 -0400 Subject: [PATCH] Fix transiently failing Selenium test of tool form re-running. Reworks addition of staleness checkers introduced in #3780. --- test/galaxy_selenium/navigates_galaxy.py | 32 +++++++++++++----------- test/selenium_tests/test_tool_form.py | 17 +++++++++---- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/test/galaxy_selenium/navigates_galaxy.py b/test/galaxy_selenium/navigates_galaxy.py index c3f0038af41..b4b4584420c 100644 --- a/test/galaxy_selenium/navigates_galaxy.py +++ b/test/galaxy_selenium/navigates_galaxy.py @@ -9,7 +9,7 @@ import random import string import time -from functools import wraps +from functools import partial, wraps import requests import yaml @@ -28,23 +28,27 @@ class NullTourCallback(object): pass +def retry_call_during_transitions(f, attempts=5, sleep=.1): + previous_attempts = 0 + while True: + try: + return f() + except Exception as e: + if previous_attempts > attempts: + raise + + if not exception_indicates_stale_element(e): + raise + + time.sleep(sleep) + previous_attempts += 1 + + def retry_during_transitions(f, attempts=5, sleep=.1): @wraps(f) def _retry(*args, **kwds): - previous_attempts = 0 - while True: - try: - return f(*args, **kwds) - except Exception as e: - if previous_attempts > attempts: - raise - - if not exception_indicates_stale_element(e): - raise - - time.sleep(sleep) - previous_attempts += 1 + retry_call_during_transitions(partial(f, *args, **kwds), attempts=attempts, sleep=sleep) return _retry diff --git a/test/selenium_tests/test_tool_form.py b/test/selenium_tests/test_tool_form.py index 7156bbd7a9d..686f9fbb810 100644 --- a/test/selenium_tests/test_tool_form.py +++ b/test/selenium_tests/test_tool_form.py @@ -4,6 +4,8 @@ from .framework import ( UsesHistoryItemAssertions, ) +from galaxy_selenium.navigates_galaxy import retry_call_during_transitions + class ToolFormTestCase(SeleniumTestCase, UsesHistoryItemAssertions): @@ -65,11 +67,16 @@ class ToolFormTestCase(SeleniumTestCase, UsesHistoryItemAssertions): self.history_panel_wait_for_hid_ok(1) self.hda_click_primary_action_button(1, "rerun") - inttest_div_element = self.tool_parameter_div("inttest") - inttest_input_element = inttest_div_element.find_element_by_css_selector("input") - recorded_val = inttest_input_element.get_attribute("value") - # Assert form re-rendered with correct value in textbox. - assert recorded_val == "42", recorded_val + def check_recorded_val(): + inttest_div_element = self.tool_parameter_div("inttest") + inttest_input_element = inttest_div_element.find_element_by_css_selector("input") + recorded_val = inttest_input_element.get_attribute("value") + # Assert form re-rendered with correct value in textbox. + assert recorded_val == "42", recorded_val + + # These form entries seem to be replaced/updated occasionally + # causing stale elements. + retry_call_during_transitions(check_recorded_val) self.tool_execute() self.history_panel_wait_for_hid_ok(2)