This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
alert_spec.rb
99 lines (86 loc) · 2.83 KB
/
alert_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require File.expand_path("../spec_helper", __FILE__)
describe 'Alert API' do
bug "https://github.com/detro/ghostdriver/issues/20", :phantomjs do
not_compliant_on :safari do
before do
browser.goto WatirSpec.url_for("alerts.html")
end
after do
browser.alert.ok if browser.alert.exists?
end
context 'alert' do
describe '#text' do
it 'returns text of alert' do
browser.button(id: 'alert').click
expect(browser.alert.text).to include('ok')
end
end
describe '#exists?' do
it 'returns false if alert is not present' do
expect(browser.alert).to_not exist
end
it 'returns true if alert is present' do
browser.button(id: 'alert').click
browser.wait_until(10) { browser.alert.exists? }
end
end
describe '#ok' do
it 'closes alert' do
browser.button(id: 'alert').click
browser.alert.ok
expect(browser.alert).to_not exist
end
end
bug "https://code.google.com/p/chromedriver/issues/detail?id=26", [:chrome, :macosx] do
describe '#close' do
it 'closes alert' do
browser.button(id: 'alert').click
browser.alert.when_present.close
expect(browser.alert).to_not exist
end
end
end
describe 'when_present' do
it 'waits until alert is present and goes on' do
browser.button(id: 'timeout-alert').click
browser.alert.when_present.ok
expect(browser.alert).to_not exist
end
it 'raises error if alert is not present after timeout' do
expect {
browser.alert.when_present(0.1).ok
}.to raise_error(Watir::Wait::TimeoutError)
end
end
end
context 'confirm' do
describe '#ok' do
it 'accepts confirm' do
browser.button(id: 'confirm').click
browser.alert.ok
expect(browser.button(id: 'confirm').value).to eq "true"
end
end
describe '#close' do
it 'cancels confirm' do
browser.button(id: 'confirm').click
browser.alert.when_present.close
expect(browser.button(id: 'confirm').value).to eq "false"
end
end
end
context 'prompt' do
describe '#set' do
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do
it 'enters text to prompt' do
browser.button(id: 'prompt').click
browser.alert.set 'My Name'
browser.alert.ok
expect(browser.button(id: 'prompt').value).to eq 'My Name'
end
end
end
end
end
end
end