summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-08-12 11:41:30 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-12 11:41:30 +0200
commit2ceab54b474ed3938d74f40bbd8eaeec5ffee4e9 (patch)
treeeb43a109c71768ee2bea25f7035b8277f4001f25
parentf5a4aaf9d349d477b406f266469e0cd13a572013 (diff)
Spend some time in twisted reactor before accessing page.
- Increase likelihood that page and related resources got delivered before asserting changes using selenium.
-rw-r--r--service/test/functional/features/steps/common.py22
-rw-r--r--service/test/functional/features/steps/mail_list.py3
2 files changed, 24 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
+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
diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py
index 2b1092c5..0822cd75 100644
--- a/service/test/functional/features/steps/mail_list.py
+++ b/service/test/functional/features/steps/mail_list.py
@@ -102,7 +102,8 @@ def impl(context):
context.current_mail_id = last_email().get_attribute('id')
last_email().find_element_by_tag_name('input').click()
find_element_by_id(context, 'delete-selected').click()
- assert context.current_mail_id != find_elements_by_css_selector(context, '#mail-list li span a')[0]
+ spend_time_in_reactor()
+ assert 0 == len(context.browser.find_element_by_id('mail-list').find_elements_by_tag_name('li'))
@when('I check all emails')