Created
September 27, 2011 14:44
-
-
Save joelcogen/1245226 to your computer and use it in GitHub Desktop.
JS confirm dialog testing with Cucumber, Capybara, Rails 2 and 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then I expect to click "OK" on a confirmation box saying "Are you sure?" | |
And I press "Delete" | |
And the confirmation box should have been displayed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I expect to click "([^"]*)" on a confirmation box saying "([^"]*)"$/ do |option, message| | |
retval = (option == 'OK') ? 'true' : 'false' | |
page.evaluate_script("window.confirm = function (msg) { | |
document.cookie = msg | |
return #{retval} | |
}") | |
@expected_message = message.gsub("\\n", "\n") | |
end | |
When /^the confirmation box should have been displayed$/ do | |
assert page.evaluate_script('document.cookie').include?(@expected_message), | |
"Expected confirm box with message: '#{@expected_message}'" + | |
" got: '#{page.evaluate_script('document.cookie')}'" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then "Delete" should have a confirmation saying "Are you sure?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^"([^\"]*)" should have a confirmation saying "([^\"]*)"$/ do |locator, message| | |
el = find_button(locator) || find_link(locator) | |
el['data-confirm'].should eql(message.gsub("\\n", "\n")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment