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
/
after_hooks_spec.rb
177 lines (155 loc) · 6.56 KB
/
after_hooks_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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
require File.expand_path("../spec_helper", __FILE__)
describe "Browser::AfterHooks" do
describe "#add" do
it "raises ArgumentError when not given any arguments" do
expect { browser.after_hooks.add }.to raise_error(ArgumentError)
end
it "runs the given proc on each page load" do
output = ''
proc = Proc.new { |browser| output << browser.text }
begin
browser.after_hooks.add(proc)
browser.goto(WatirSpec.url_for("non_control_elements.html"))
expect(output).to include('Dubito, ergo cogito, ergo sum')
ensure
browser.after_hooks.delete(proc)
end
end
end
describe "#delete" do
it "removes a previously added after_hook" do
output = ''
after_hook = lambda{ |browser| output << browser.text }
browser.after_hooks.add(after_hook)
browser.goto(WatirSpec.url_for("non_control_elements.html"))
expect(output).to include('Dubito, ergo cogito, ergo sum')
browser.after_hooks.delete(after_hook)
browser.goto(WatirSpec.url_for("definition_lists.html"))
expect(output).to_not include('definition_lists')
end
end
describe "#run" do
after(:each) do
browser.window(index: 0).use
browser.after_hooks.delete @page_after_hook
end
it "runs after_hooks after Browser#goto" do
@page_after_hook = Proc.new { @yield = browser.title == "The font element" }
browser.after_hooks.add @page_after_hook
browser.goto WatirSpec.url_for("font.html")
expect(@yield).to be true
end
it "runs after_hooks after Browser#refresh" do
browser.goto WatirSpec.url_for("font.html")
@page_after_hook = Proc.new { @yield = browser.title == "The font element" }
browser.after_hooks.add @page_after_hook
browser.refresh
expect(@yield).to be true
end
it "runs after_hooks after Element#click" do
browser.goto(WatirSpec.url_for("non_control_elements.html"))
@page_after_hook = Proc.new do
Watir::Wait.while { browser.title.empty? }
@yield = browser.title == "Non-control elements"
end
browser.after_hooks.add @page_after_hook
browser.link(index: 1).click
expect(@yield).to be true
end
bug "AutomatedTester: 'known bug with execute script'", :firefox do
it "runs after_hooks after Element#submit" do
browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
@page_after_hook = Proc.new { @yield = browser.div(id: 'messages').text == 'submit' }
browser.after_hooks.add @page_after_hook
browser.form(id: "new_user").submit
expect(@yield).to be true
end
end
not_compliant_on :safari do
bug "Actions Endpoint Not Yet Implemented", :firefox do
it "runs after_hooks after Element#double_click" do
browser.goto(WatirSpec.url_for("non_control_elements.html"))
@page_after_hook = Proc.new { @yield = browser.title == "Non-control elements" }
browser.after_hooks.add @page_after_hook
browser.div(id: 'html_test').double_click
expect(@yield).to be true
end
end
end
not_compliant_on :safari do
bug "Actions Endpoint Not Yet Implemented", :firefox do
it "runs after_hooks after Element#right_click" do
browser.goto(WatirSpec.url_for("right_click.html"))
@page_after_hook = Proc.new { @yield = browser.title == "Right Click Test" }
browser.after_hooks.add @page_after_hook
browser.div(id: "click").right_click
expect(@yield).to be true
end
end
end
bug "https://github.com/detro/ghostdriver/issues/20", :phantomjs do
not_compliant_on :safari do
it "runs after_hooks after Alert#ok" do
browser.goto(WatirSpec.url_for("alerts.html"))
@page_after_hook = Proc.new { @yield = browser.title == "Alerts" }
browser.after_hooks.add @page_after_hook
browser.after_hooks.without { browser.button(id: 'alert').click }
browser.alert.ok
expect(@yield).to be true
end
bug "https://code.google.com/p/chromedriver/issues/detail?id=26", [:chrome, :macosx] do
it "runs after_hooks after Alert#close" do
browser.goto(WatirSpec.url_for("alerts.html"))
@page_after_hook = Proc.new { @yield = browser.title == "Alerts" }
browser.after_hooks.add @page_after_hook
browser.after_hooks.without { browser.button(id: 'alert').click }
browser.alert.close
expect(@yield).to be true
end
end
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1279211", :firefox do
it "raises UnhandledAlertError error when running error checks with alert present" do
url = WatirSpec.url_for("alerts.html")
@page_after_hook = Proc.new { browser.url }
browser.after_hooks.add @page_after_hook
browser.goto url
expect { browser.button(id: "alert").click }.to raise_error(Selenium::WebDriver::Error::UnhandledAlertError)
not_compliant_on :ff_legacy do
browser.alert.ok
end
end
end
it "does not raise error when running error checks using #after_hooks#without with alert present" do
url = WatirSpec.url_for("alerts.html")
@page_after_hook = Proc.new { browser.url }
browser.after_hooks.add @page_after_hook
browser.goto url
expect { browser.after_hooks.without {browser.button(id: "alert").click} }.to_not raise_error
browser.alert.ok
end
it "does not raise error if no error checks are defined with alert present" do
url = WatirSpec.url_for("alerts.html")
@page_after_hook = Proc.new { browser.url }
browser.after_hooks.add @page_after_hook
browser.goto url
browser.after_hooks.delete @page_after_hook
expect { browser.button(id: "alert").click }.to_not raise_error
browser.alert.ok
end
end
end
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1223277", :firefox do
it "does not raise error when running error checks on closed window" do
url = WatirSpec.url_for("window_switching.html")
@page_after_hook = Proc.new { browser.url }
browser.after_hooks.add @page_after_hook
browser.goto url
browser.a(id: "open").click
window = browser.window(title: "closeable window")
window.use
expect { browser.a(id: "close").click }.to_not raise_error
browser.window(index: 0).use
end
end
end
end