Catch WebDriverException

This commit is contained in:
Jay Zoldak
2013-03-04 15:50:25 -05:00
parent b9e5ed9525
commit 3cec8f1a76
2 changed files with 16 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
from lettuce import world, step
from common import *
import time
from selenium.common.exceptions import WebDriverException
from nose.tools import assert_equal
from nose.tools import assert_true
@@ -42,7 +43,11 @@ def edit_the_name_of_a_policy_key(step):
@step(u'I press the "([^"]*)" notification button$')
def press_the_notification_button(step, name):
world.browser.click_link_by_text(name)
try:
world.browser.click_link_by_text(name)
except WebDriverException, e:
css = 'a.%s-button' % name.lower()
css_click_at(css)
@step(u'I edit the value of a policy key$')

View File

@@ -3,6 +3,7 @@ from lettuce.django import django_url
from nose.tools import assert_true
from nose.tools import assert_equal
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from terrain.factories import UserFactory, RegistrationFactory, UserProfileFactory
from terrain.factories import CourseFactory, GroupFactory
@@ -95,10 +96,16 @@ def assert_css_with_text(css, text):
def css_click(css):
'''
Rather than click in the middle of an element,
click in the upper left
First try to use the regular click method,
but if clicking in the middle of an element
doesn't work it might be that it thinks some other
element is on top of it there so click in the upper left
'''
css_click_at(css)
try:
assert_true(world.browser.is_element_present_by_css(css, 5))
world.browser.find_by_css(css).first.click()
except WebDriverException, e:
css_click_at(css)
def css_click_at(css, x=10, y=10):