From d411d38b8160e48540ee13e36fdfd6d06b8709c8 Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Thu, 10 Sep 2015 14:54:45 +0200 Subject: Add 'with ImplicitWait' to allow shorter timeouts - necessary if elements do not exist, selenium seems to wait the entire explict timeout in this case --- service/test/functional/features/environment.py | 3 ++- service/test/functional/features/steps/common.py | 15 ++++++++++++++- service/test/functional/features/steps/mail_list.py | 12 +++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'service/test') diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index 248b01fa..53b13047 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -24,6 +24,7 @@ from test.support.integration import AppTestClient from selenium import webdriver from pixelated.resources.features_resource import FeaturesResource +from steps.common import * setup() @@ -53,7 +54,7 @@ def before_feature(context, feature): # context.browser = webdriver.Firefox() context.browser = webdriver.PhantomJS() context.browser.set_window_size(1280, 1024) - context.browser.implicitly_wait(10) + context.browser.implicitly_wait(DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S) context.browser.set_page_load_timeout(60) # wait for data context.browser.get('http://localhost:8889/') diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py index b45f86db..d9db92b0 100644 --- a/service/test/functional/features/steps/common.py +++ b/service/test/functional/features/steps/common.py @@ -28,9 +28,22 @@ LOADING = 'loading' TIMEOUT_IN_S = 20 +DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S = 10.0 + + +class ImplicitWait(object): + def __init__(self, context, timeout=5.0): + self._context = context + self._timeout = timeout + + def __enter__(self): + self._context.browser.implicitly_wait(self._timeout) + + def __exit__(self, exc_type, exc_val, exc_tb): + self._context.browser.implicitly_wait(DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S) + 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)) diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py index bae77c52..7962ee28 100644 --- a/service/test/functional/features/steps/mail_list.py +++ b/service/test/functional/features/steps/mail_list.py @@ -15,7 +15,6 @@ # along with Pixelated. If not, see . from common import * from selenium.common.exceptions import NoSuchElementException -from time import sleep def find_current_mail(context): @@ -94,16 +93,19 @@ def impl(context): @when('I delete the email') def impl(context): def last_email(): - return wait_until_elements_are_visible_by_locator(context, (By.CSS_SELECTOR, '#mail-list li'))[0] - context.current_mail_id = last_email().get_attribute('id') - last_email().find_element_by_tag_name('input').click() + return wait_until_element_is_visible_by_locator(context, (By.CSS_SELECTOR, '#mail-list li')) + mail = last_email() + context.current_mail_id = mail.get_attribute('id') + mail.find_element_by_tag_name('input').click() find_element_by_id(context, 'delete-selected').click() _wait_for_mail_list_to_be_empty(context) def _wait_for_mail_list_to_be_empty(context): wait_for_loading_to_finish(context) - assert 0 == len(context.browser.find_elements_by_css_selector('#mail-list li')) + + with ImplicitWait(context, timeout=0.1): + assert 0 == len(context.browser.find_elements_by_css_selector('#mail-list li')) @when('I check all emails') -- cgit v1.2.3