Skip to content

Commit

Permalink
Alert presence steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ggozad committed Aug 27, 2015
1 parent 9ea60ea commit 283e02d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ Changelog
1.4 - Unreleased
----------------

- Alert presence steps.
[ggozad]

1.3 - 2015-08-18
----------------
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -403,6 +403,8 @@ When *behaving* is installed, it creates three scripts to help you test mail, gc
* Then "``name``" should not be valid
* Then "``name``" should be required
* Then "``name``" should not be required
* Then I should see an alert
* Then I should see an alert within ``timeout`` seconds

* Persona interaction & variables

Expand Down
21 changes: 21 additions & 0 deletions src/behaving/web/steps/forms.py
Expand Up @@ -2,7 +2,9 @@
from behave import step
from splinter.exceptions import ElementDoesNotExist
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoAlertPresentException
from behaving.personas.persona import persona_vars
from behaving.web.steps.basic import _retry


@step(u'I fill in "{name}" with "{value}"')
Expand Down Expand Up @@ -193,6 +195,25 @@ def field_is_not_required(context, name):
'Field is required'


@step(u'I should see an alert')
def alert_is_present(context):
try:
assert context.browser.get_alert(), u'Alert not found'
except NoAlertPresentException:
assert False, u'Alert not found'


@step(u'I should see an alert within {timeout:d} seconds')
def alert_is_present_timeout(context, timeout):
def check():
try:
alert = context.browser.get_alert(), u'Alert not found'
return alert is not None
except NoAlertPresentException:
return False
assert _retry(check, timeout), u'Alert not found'


@step(u'I enter "{text}" to the alert')
@persona_vars
def set_alert_text(context, text):
Expand Down

0 comments on commit 283e02d

Please sign in to comment.