Added functionality to bypass alerts

This is done with the following steps:
'I confirm all alerts' means that all alert and confirm windows are returned and returned true respectively
'I dismiss all alerts' means that all confirm windows are returned false
'I answer all prompts with "([^"]*)"' means that all prompts are returned with the given string

Please note that these settings are on a PER PAGE basis.  This means that for best results, the step must be given right before the alert is generated.
This commit is contained in:
JonahStanley
2013-06-05 15:08:58 -04:00
parent b312944dcf
commit acc743eea8
2 changed files with 27 additions and 14 deletions

View File

@@ -159,3 +159,18 @@ def registered_edx_user(step, uname):
@step(u'All dialogs should be closed$')
def dialogs_are_closed(step):
assert world.dialogs_closed()
@step('I confirm all alerts')
def i_confirm_with_ok(step):
world.browser.execute_script('window.confirm = function(){return true;} ; window.alert = function(){return;}')
@step('I dismiss all alerts')
def i_dismiss_with_ok(step):
world.browser.execute_script('window.confirm = function(){return false;}')
@step('I answer all prompts with "([^"]*)"')
def i_answer_prompts_with(step, prompt):
world.browser.execute_script('window.prompt = function(){return %s;}') % prompt