Commit e20f2109 by Will Daly

Updated static-pages test to add retry logic

parent 08168ec6
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from lettuce import world, step from lettuce import world, step
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from nose.tools import assert_true # pylint: disable=E0611
@step(u'I go to the static pages page') @step(u'I go to the static pages page')
...@@ -21,18 +22,21 @@ def add_page(_step): ...@@ -21,18 +22,21 @@ def add_page(_step):
@step(u'I should( not)? see a "([^"]*)" static page$') @step(u'I should( not)? see a "([^"]*)" static page$')
def see_page(_step, doesnt, page): def see_page(_step, doesnt, page):
index = get_index(page)
if doesnt: should_exist = not doesnt
assert index == -1
else: # Need to retry here because the element
assert index != -1 # will sometimes exist before the HTML content is loaded
exists_func = lambda(driver): page_exists(page) == should_exist
world.wait_for(exists_func)
assert_true(exists_func(None))
@step(u'I "([^"]*)" the "([^"]*)" page$') @step(u'I "([^"]*)" the "([^"]*)" page$')
def click_edit_delete(_step, edit_delete, page): def click_edit_delete(_step, edit_delete, page):
button_css = 'a.%s-button' % edit_delete button_css = 'a.%s-button' % edit_delete
index = get_index(page) index = get_index(page)
assert index != -1 assert index is not None
world.css_click(button_css, index=index) world.css_click(button_css, index=index)
...@@ -54,4 +58,7 @@ def get_index(name): ...@@ -54,4 +58,7 @@ def get_index(name):
for i in range(len(all_pages)): for i in range(len(all_pages)):
if world.css_html(page_name_css, index=i) == '\n {name}\n'.format(name=name): if world.css_html(page_name_css, index=i) == '\n {name}\n'.format(name=name):
return i return i
return -1 return None
def page_exists(page):
return get_index(page) is not None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment