edx/edx-platform — pull request #77 by JonahStanley (2013-06-05 19:38:22+00:00)
Title: Jonahstanley/fix alert tests

Suggested Reviewers @wedaly @cahrens @jzoldak

In this pull request, I have fixed the issue of chrome hanging on alerts.

This was done by changing how alerts work on the javascript level:
Alerts are created through window.alert(), window.confirm(), window.prompt()
These methods have some functionality that creates the popup box and upon the user clicking/typing either return (alert), return true or false (confirm) or return with a string (prompt)

Selenium can inject javascript through world.browser.execute_script()
Now, there are steps to cut out the middleman so to speak.
"I confirm all alerts" will redefine
window.alert = function(){return;}
window.confirm = function(){return true;}

"I dismiss all alerts" will redefine
window.confirm = function(){return false;}

'I answer all prompts with "([^"]*)"' will redefine
window.prompt = function(){return %s} %prompt

The window variable only persists on a given page so changing these functions will only affect the page they are on. While this does make it safer to modify these functions, this also means that these steps must be called right before the alert is generated.

In following this, I have also fixed the features that required this functionality and they all now work on my local machine.