Skip to content

Instantly share code, notes, and snippets.

@gongo
Created February 22, 2013 00:57
Show Gist options
  • Save gongo/5009937 to your computer and use it in GitHub Desktop.
Save gongo/5009937 to your computer and use it in GitHub Desktop.
Feature: アラートとコンフォーム
Scenario: hoge
Given アクセス
When alertボタンをクリック
Then あらーーーと
Scenario: fuga
Given アクセス
When confirmボタンをクリック
Then こんふぉーーむ
<!DOCTYPE html>
<html>
<head>
<title>Georgia Point Kure</title>
<meta charset='UTF-8'>
</head>
<body>
<input type="button" id="alert_button" onclick="alert('aiueo')" value="alert" />
<input type="button" id="confirm_button" onclick="if (confirm('ok?')) { document.getElementById('confirm_result').innerHTML = 'ok'; } else { document.getElementById('confirm_result').innerHTML = 'no...'; }" value="confirm" />
<div id="confirm_result"></div>
</body>
</html>
# -*- coding: utf-8 -*-
step "アクセス" do
visit 'http://localhost:5000'
end
step "alertボタンをクリック" do
click_button 'alert_button'
end
step "confirmボタンをクリック" do
click_button 'confirm_button'
end
step "あらーーーと" do
alert = page.driver.browser.switch_to.alert
expect(alert.text).to eq("aiueo")
alert.accept
end
step "こんふぉーーむ" do
alert = page.driver.browser.switch_to.alert
expect(alert.text).to eq("ok?")
alert.accept # <= confirm ダイアログの OK
#alert.dismiss # <= confirm ダイアログの キャンセル
expect(find('#confirm_result')).to have_text('ok')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment