Skip to content

Instantly share code, notes, and snippets.

@kyamaguchi
Created November 30, 2011 07:56
Show Gist options
  • Save kyamaguchi/1408387 to your computer and use it in GitHub Desktop.
Save kyamaguchi/1408387 to your computer and use it in GitHub Desktop.
Confirmation in integration test
# selenium-webdriver (2.12.2) (with rails3)
def assert_confirmation(message, choice = 'ok')
if selenium?
assert_equal message, page.driver.browser.switch_to.alert.text
if choice == 'ok'
page.driver.browser.switch_to.alert.accept
elsif choice == 'cancel'
page.driver.browser.switch_to.alert.dismiss
end
else
assert true
end
end
# old selenium webdriver (with rails2)
def assert_confirmation(message, choice = 'ok')
if selenium?
assert selenium.is_confirmation_present
assert_equal message, selenium.get_confirmation
if choice == 'ok'
selenium.choose_ok_on_next_confirmation
elsif choice == 'cancel'
selenium.choose_cancel_on_next_confirmation
end
else
assert true
end
end
assert_confirmation("よろしいでしょうか") if selenium?
# http://stackoverflow.com/questions/2828342/capybara-selenium-and-javascript-destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment