From 2ceab54b474ed3938d74f40bbd8eaeec5ffee4e9 Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Wed, 12 Aug 2015 11:41:30 +0200 Subject: Spend some time in twisted reactor before accessing page. - Increase likelihood that page and related resources got delivered before asserting changes using selenium. --- service/test/functional/features/steps/common.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'service/test/functional/features/steps/common.py') diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py index 1ef3d35b..96c51a6e 100644 --- a/service/test/functional/features/steps/common.py +++ b/service/test/functional/features/steps/common.py @@ -13,10 +13,14 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . +from crochet import wait_for + from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait from selenium.common.exceptions import TimeoutException +from twisted.internet import reactor +from twisted.internet import defer from test.support.integration import MailBuilder @@ -24,11 +28,13 @@ TIMEOUT_IN_S = 20 def wait_until_element_is_invisible_by_locator(context, locator_tuple, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) wait.until(EC.invisibility_of_element_located(locator_tuple)) def wait_until_element_is_deleted(context, locator_tuple, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) wait.until(lambda s: len(s.find_elements(locator_tuple[0], locator_tuple[1])) == 0) @@ -38,18 +44,21 @@ def wait_for_user_alert_to_disapear(context, timeout=TIMEOUT_IN_S): def wait_until_elements_are_visible_by_locator(context, locator_tuple, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) wait.until(EC.presence_of_all_elements_located(locator_tuple)) return context.browser.find_elements(locator_tuple[0], locator_tuple[1]) def wait_until_elements_are_visible_by_xpath(context, locator_tuple, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) wait.until(EC.presence_of_all_elements_located(locator_tuple)) return context.browser.find_elements(locator_tuple[0], locator_tuple[1]) def wait_until_element_is_visible_by_locator(context, locator_tuple, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) wait.until(EC.visibility_of_element_located(locator_tuple)) return context.browser.find_element(locator_tuple[0], locator_tuple[1]) @@ -112,6 +121,7 @@ def element_should_have_content(context, css_selector, content): def wait_until_button_is_visible(context, title, timeout=TIMEOUT_IN_S): + spend_time_in_reactor() wait = WebDriverWait(context.browser, timeout) locator_tuple = (By.XPATH, ("//%s[contains(.,'%s')]" % ('button', title))) wait.until(EC.visibility_of_element_located(locator_tuple)) @@ -147,3 +157,15 @@ def get_console_log(context): def create_email(context): input_mail = MailBuilder().build_input_mail() context.client.add_mail_to_inbox(input_mail) + + +@wait_for(timeout=5.0) +def spend_time_in_reactor(reactor_time=1.0): + d = defer.Deferred() + + def done_waiting(): + d.callback(None) + + reactor.callLater(reactor_time, done_waiting) + + return d -- cgit v1.2.3