forked from watir/watirspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_spec.rb
142 lines (115 loc) · 3.65 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require File.expand_path("../spec_helper", __FILE__)
describe 'Alert API' do
bug "https://github.com/detro/ghostdriver/issues/20", :phantomjs do
before do
browser.goto WatirSpec.url_for("alerts.html")
end
after do
browser.alert.close if browser.alert.exists?
end
context 'alert' do
describe '#text' do
it 'returns text of alert' do
not_compliant_on :watir_classic do
browser.button(:id => 'alert').click
end
deviates_on :watir_classic do
browser.button(:id => 'alert').click_no_wait
end
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
not_compliant_on :watir_classic do
browser.button(:id => 'alert').click
end
deviates_on :watir_classic do
browser.button(:id => 'alert').click_no_wait
end
browser.wait_until(10) { browser.alert.exists? }
end
end
describe '#ok' do
it 'closes alert' do
not_compliant_on :watir_classic do
browser.button(:id => 'alert').click
end
deviates_on :watir_classic do
browser.button(:id => 'alert').click_no_wait
end
browser.alert.ok
expect(browser.alert).to_not exist
end
end
describe '#close' do
it 'closes alert' do
not_compliant_on :watir_classic do
browser.button(:id => 'alert').click
end
deviates_on :watir_classic do
browser.button(:id => 'alert').click_no_wait
end
browser.alert.when_present.close
expect(browser.alert).to_not exist
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.close
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).close
}.to raise_error(Watir::Wait::TimeoutError)
end
end
end
context 'confirm' do
describe '#ok' do
it 'accepts confirm' do
not_compliant_on :watir_classic do
browser.button(:id => 'confirm').click
end
deviates_on :watir_classic do
browser.button(:id => 'confirm').click_no_wait
end
browser.alert.ok
expect(browser.button(:id => 'confirm').value).to eq "true"
end
end
describe '#close' do
it 'cancels confirm' do
not_compliant_on :watir_classic do
browser.button(:id => 'confirm').click
end
deviates_on :watir_classic do
browser.button(:id => 'confirm').click_no_wait
end
browser.alert.when_present.close
expect(browser.button(:id => 'confirm').value).to eq "false"
end
end
end
context 'prompt' do
describe '#set' do
it 'enters text to prompt' do
not_compliant_on :watir_classic do
browser.button(:id => 'prompt').click
end
deviates_on :watir_classic do
browser.button(:id => 'prompt').click_no_wait
end
browser.alert.set 'My Name'
browser.alert.ok
expect(browser.button(:id => 'prompt').value).to eq 'My Name'
end
end
end
end
end