operawatir 0.3-jruby → 0.3.2-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -2
- data/LICENSE +1 -1
- data/Rakefile +7 -8
- data/VERSION +1 -1
- data/bin/desktopwatir +3 -0
- data/bin/operawatir +2 -2
- data/lib/operadriver/webdriver-opera.jar +0 -0
- data/lib/operawatir.rb +14 -8
- data/lib/operawatir/browser.rb +49 -38
- data/lib/operawatir/compat/collection.rb +6 -0
- data/lib/operawatir/compat/element.rb +5 -2
- data/lib/operawatir/compat/element_finders.rb +19 -0
- data/lib/operawatir/desktop-waiter.rb +144 -0
- data/lib/operawatir/desktop_browser.rb +506 -0
- data/lib/operawatir/desktop_common.rb +111 -0
- data/lib/operawatir/desktop_container.rb +252 -0
- data/lib/operawatir/desktop_enums.rb +42 -0
- data/lib/operawatir/desktop_exceptions.rb +16 -0
- data/lib/operawatir/element.rb +6 -6
- data/lib/operawatir/exceptions.rb +3 -0
- data/lib/operawatir/keys.rb +116 -0
- data/lib/operawatir/platform.rb +59 -0
- data/lib/operawatir/quickwidgets.rb +3 -0
- data/lib/operawatir/quickwidgets/quick_addressfield.rb +23 -0
- data/lib/operawatir/quickwidgets/quick_button.rb +151 -0
- data/lib/operawatir/quickwidgets/quick_checkbox.rb +58 -0
- data/lib/operawatir/quickwidgets/quick_dialogtab.rb +23 -0
- data/lib/operawatir/quickwidgets/quick_dropdown.rb +27 -0
- data/lib/operawatir/quickwidgets/quick_editfield.rb +115 -0
- data/lib/operawatir/quickwidgets/quick_label.rb +12 -0
- data/lib/operawatir/quickwidgets/quick_radiobutton.rb +11 -0
- data/lib/operawatir/quickwidgets/quick_searchfield.rb +25 -0
- data/lib/operawatir/quickwidgets/quick_tab.rb +66 -0
- data/lib/operawatir/quickwidgets/quick_thumbnail.rb +26 -0
- data/lib/operawatir/quickwidgets/quick_toolbar.rb +11 -0
- data/lib/operawatir/quickwidgets/quick_treeitem.rb +157 -0
- data/lib/operawatir/quickwidgets/quick_treeview.rb +27 -0
- data/lib/operawatir/quickwidgets/quick_widget.rb +369 -0
- data/lib/operawatir/quickwidgets/quick_window.rb +150 -0
- data/lib/operawatir/selector.rb +1 -1
- data/lib/operawatir/version.rb +0 -1
- data/lib/operawatir/window.rb +9 -0
- data/operawatir.gemspec +382 -0
- data/spec/new_watirspec/browser_spec.rb +279 -0
- data/spec/new_watirspec/clipboard_spec.rb +79 -0
- data/spec/new_watirspec/collection_spec.rb +387 -0
- data/spec/new_watirspec/element_spec.rb +456 -0
- data/spec/new_watirspec/guards.rb +39 -0
- data/spec/new_watirspec/keys_spec.rb +206 -0
- data/spec/new_watirspec/server.rb +91 -0
- data/spec/new_watirspec/watirspec_helper.rb +62 -0
- data/spec/new_watirspec/window_spec.rb +370 -0
- data/utils/launchers/launcher-mac +0 -0
- metadata +191 -28
- data/.gitmodules +0 -3
@@ -0,0 +1,456 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../watirspec_helper', __FILE__)
|
3
|
+
|
4
|
+
describe 'Element' do
|
5
|
+
# Direct attribute access
|
6
|
+
before :each do
|
7
|
+
browser.url = fixture('non_control_elements.html')
|
8
|
+
|
9
|
+
@element = window.find_by_id('descartes').first
|
10
|
+
@list = window.find_by_id('navbar').first
|
11
|
+
@leaf = window.find_by_id('link_2').first
|
12
|
+
end
|
13
|
+
|
14
|
+
# parent
|
15
|
+
describe '#parent' do
|
16
|
+
it 'is the parent element of an element' do
|
17
|
+
# Two .parent to get to an IDed element
|
18
|
+
@element.parent.parent.attr(:id).should == 'promo'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is nil for the root element' do
|
22
|
+
window.find_by_tag(:html).first.parent.should == nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# attr(what, value=nil)
|
27
|
+
describe '#attr' do
|
28
|
+
it 'gets the value of the given attribute' do
|
29
|
+
@element.attr(:class).should == 'descartes'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'uses underscores instead of dashes' do
|
33
|
+
@leaf.attr(:data_fixture).should == 'leaf'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is nil when the attribute does not exist' do
|
37
|
+
@element.attr(:hoobaflooba).should == nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'sugar' do
|
42
|
+
it 'provides direct access to the element\'s attributes' do
|
43
|
+
@element.id.should == @element.attr(:id)
|
44
|
+
@element.class_name.should == @element.attr(:class)
|
45
|
+
@element.title.should == @element.attr(:title)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'uses underscores instead of dashes' do
|
49
|
+
@leaf.data_fixture.should == 'leaf'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'is nil when the attribute does not exist' do
|
53
|
+
@element.hoobaflooba.should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# text
|
58
|
+
describe '#text' do
|
59
|
+
it 'is the text contained by the element' do
|
60
|
+
@element.text.should == 'Dubito, ergo cogito, ergo sum.'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'is an empty string when there is no text' do
|
64
|
+
window.find_by_tag(:div).first.text.should == ''
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#text=' do
|
69
|
+
it 'sets the text content of the element' do
|
70
|
+
window.find_by_tag(:em).first.text = 'test'
|
71
|
+
@element.text.should == 'Dubito, test, ergo sum.'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'overwrites child elements' do
|
75
|
+
@element.text = 'test'
|
76
|
+
window.find_by_tag(:em).should be_empty
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# html
|
81
|
+
describe '#html' do
|
82
|
+
it 'is the outer HTML of the element' do
|
83
|
+
@element.html.should == "<strong id='descartes' class='descartes'>Dubito, <em class='important-class' id='important-id' title='ergo cogito'>ergo cogito</em>, ergo sum.</strong>"
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'is an empty string if the element contains no text or html' do
|
87
|
+
window.find_by_tag(:body).div.first.html.should == ''
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#html=' do
|
92
|
+
it 'sets the outer HTML of the element' do
|
93
|
+
@element.em.first.html = '<b>test</b>'
|
94
|
+
@element.html.should == "<strong id='descartes' class='descartes'>Dubito, <b>test</b>, ergo sum.</strong>"
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'creates child elements' do
|
98
|
+
@element.em.first.html = "<b>one</b> <b class='test'>two</b>"
|
99
|
+
@element.em.length.should == 2
|
100
|
+
@element.em[1].attr(:class).should == 'test'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# tag_name
|
105
|
+
describe '#tag_name' do
|
106
|
+
it 'is the tag name of an element' do
|
107
|
+
@element.tag_name.should match /strong/i
|
108
|
+
@list.tag_name.should match /ul/i
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# hash
|
113
|
+
describe '#visual_hash' do
|
114
|
+
it 'is the MD5 hash of the screenshot of the element' do
|
115
|
+
window.url = fixture('images.html')
|
116
|
+
# this hash is from from Watir 1
|
117
|
+
image = window.find_by_tag(:img)[1].visual_hash.should == '0x45688373bcf08d9ecf111ecb2bcb7c4e'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# states
|
122
|
+
# ------
|
123
|
+
|
124
|
+
# checked?
|
125
|
+
describe '#checked?' do
|
126
|
+
before :each do
|
127
|
+
browser.url = fixture('forms_with_input_elements.html')
|
128
|
+
|
129
|
+
@textbox = window.find_by_id('new_user_username').first
|
130
|
+
@checkbox_checked = window.find_by_id('new_user_interests_books').first
|
131
|
+
@checkbox_unchecked = window.find_by_id('new_user_interests_cars').first
|
132
|
+
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
|
133
|
+
@radio_unchecked = window.find_by_id('new_user_newsletter_no').first
|
134
|
+
end
|
135
|
+
|
136
|
+
# TODO 'checked' is available for all <input> and <command>. Change this
|
137
|
+
# test?
|
138
|
+
it 'exists on radio button elements' do
|
139
|
+
@radio_checked.should respond_to :checked?
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'exists on checkbox elements' do
|
143
|
+
@checkbox_checked.should respond_to :checked?
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'does not exist on non-checkbox or radio button elements' do
|
147
|
+
@textbox.should_not respond_to :checked?
|
148
|
+
@element.should_not respond_to :checked?
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'is true if a checkbox is checked' do
|
152
|
+
@checkbox_checked.checked?.should be_true
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'is false if a checkbox is not checked' do
|
156
|
+
@checkbox_unchecked.checked?.should be_false
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'is true if a radio button is checked' do
|
160
|
+
@radio_checked.checked?.should be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'is false if a radio button is not checked' do
|
164
|
+
@radio_unchecked.checked?.should be_false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#selected?' do
|
169
|
+
before :each do
|
170
|
+
browser.url = fixture('forms_with_input_elements.html')
|
171
|
+
@options = window.find_by_id('new_user_country').option
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'is true if an option is selected' do
|
175
|
+
@options[1].selected?.should be_true
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'is false is an option is not selected' do
|
179
|
+
@options[5].selected?.should be_false
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'is true for multiple selected options' do
|
183
|
+
multi = window.find_by_id('new_user_languages').option
|
184
|
+
multi[1].selected?.should be_true
|
185
|
+
multi[2].selected?.should be_true
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'is false for unselected in a multiple select' do
|
189
|
+
multi = window.find_by_id('new_user_languages').option
|
190
|
+
multi[0].selected?.should be_false
|
191
|
+
multi[3].selected?.should be_false
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'is nil on non-option elements' do
|
195
|
+
@element.selected?.should be_nil
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# enabled?
|
200
|
+
describe '#enabled?' do
|
201
|
+
before :each do
|
202
|
+
browser.url = fixture('forms_with_input_elements.html')
|
203
|
+
@inputs = window.find_by_tag(:input)
|
204
|
+
end
|
205
|
+
|
206
|
+
# 'disabled' attribute is available on quite a few obscure
|
207
|
+
# elements. Toss up between limiting to common ones, all html5,
|
208
|
+
# all elements that have a .disabled property in Javascript, or
|
209
|
+
# all elements
|
210
|
+
it 'exists on input elements' do
|
211
|
+
@inputs.all? do |input|
|
212
|
+
input.respond_to? :enabled?
|
213
|
+
end.should be_true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# visible?
|
218
|
+
describe '#visible?' do
|
219
|
+
before :each do
|
220
|
+
browser.url = fixture('visible.html')
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'is true for a visible element' do
|
224
|
+
window.find_by_tag(:h1).first.visible?.should be_true
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'is false for an element with style attribute “display:none”' do
|
228
|
+
window.find_by_id('parent').first.visible?.should be_false
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'is false a child of an element with style attribute “display:none”' do
|
232
|
+
window.find_by_id('child').first.visible?.should be_false
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'is false for an element hidden by CSS' do
|
236
|
+
window.find_by_id('hidden_by_css').first.visible?.should be_false
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'is true for an element with visibility:hidden' do
|
240
|
+
window.find_by_id('invisible').first.visible?.should be_true
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
# actions
|
246
|
+
# -------
|
247
|
+
|
248
|
+
# focus!
|
249
|
+
describe '#focus!' do
|
250
|
+
before :each do
|
251
|
+
browser.url = fixture('forms_with_input_elements.html')
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'focuses the element' do
|
255
|
+
input = window.find_by_id('new_user_email').first
|
256
|
+
input.focus!
|
257
|
+
window.type('test')
|
258
|
+
input.attr(:value).should == 'test'
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'returns false if the element is disabled' do
|
262
|
+
input = window.find_by_id('new_user_species').first
|
263
|
+
input.focus!.should be_false
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# click!([x, y]) , x,y relative to element top left
|
268
|
+
describe '#click!' do
|
269
|
+
it 'follows links' do
|
270
|
+
window.find_by_id('link_3').first.click!
|
271
|
+
window.url.should match /forms_with_input_elements\.html$/
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'triggers onclick handlers' do
|
275
|
+
div = window.find_by_id('best_language').first
|
276
|
+
div.click!
|
277
|
+
div.text.should == 'Ruby!'
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'toggles checkboxes' do
|
281
|
+
browser.url = fixture('forms_with_input_elements.html')
|
282
|
+
checkbox = window.find_by_id('new_user_interests_cars').first
|
283
|
+
checkbox.checked?.should be_false
|
284
|
+
checkbox.click!
|
285
|
+
checkbox.checked?.should be_true
|
286
|
+
checkbox.click!
|
287
|
+
checkbox.checked?.should be_false
|
288
|
+
end
|
289
|
+
|
290
|
+
# TODO work out whether #selected? exists, and whether it replaces
|
291
|
+
# #checked?
|
292
|
+
it 'can click option elements' do
|
293
|
+
browser.url = fixture('forms_with_input_elements.html')
|
294
|
+
|
295
|
+
select = window.find_by_id('new_user_country')
|
296
|
+
select.click!
|
297
|
+
select.option[0].click!
|
298
|
+
select.option[0].selected?.should be_true
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe '#mouse_down!' do
|
303
|
+
it 'triggers a mousedown event' do
|
304
|
+
browser.url = fixture('mouse.html')
|
305
|
+
log = window.find_by_id('log').first
|
306
|
+
log.mouse_down! 0, 0
|
307
|
+
log.text.should include 'down'
|
308
|
+
log.mouse_up! 0, 0
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe '#mouse_up' do
|
313
|
+
it 'triggers a mouseup event' do
|
314
|
+
browser.url = fixture('mouse.html')
|
315
|
+
log = window.find_by_id('log').first
|
316
|
+
log.mouse_down! 0, 0
|
317
|
+
log.mouse_up! 0, 0
|
318
|
+
log.text.should include 'up'
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe '#mouse_move' do
|
323
|
+
it 'triggers a mousemove event' do
|
324
|
+
browser.url = fixture('mouse.html')
|
325
|
+
log = window.find_by_id('log').first
|
326
|
+
log.mouse_move! 0, 0
|
327
|
+
log.text.should include 'move'
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'moves the mouse' do
|
331
|
+
browser.url = fixture('mouse.html')
|
332
|
+
log = window.find_by_id('log').first
|
333
|
+
h1 = window.find_by_tag('h1').first
|
334
|
+
|
335
|
+
h1.mouse_down! 0, 0
|
336
|
+
h1.mouse_move! 25, 25
|
337
|
+
h1.mouse_up! 50, 50
|
338
|
+
|
339
|
+
window.eval_js('!!document.getSelection()').should be_true
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
# check!
|
344
|
+
describe '#check!' do
|
345
|
+
before :each do
|
346
|
+
browser.url = fixture('forms_with_input_elements.html')
|
347
|
+
@checkbox_unchecked = window.find_by_id('new_user_interests_cars').first
|
348
|
+
@radio_unchecked = window.find_by_id('new_user_newsletter_no').first
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'checks a checkbox' do
|
352
|
+
@checkbox_unchecked.check!
|
353
|
+
@checkbox_unchecked.checked?.should be_true
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'checks a radio button' do
|
357
|
+
@radio_unchecked.check!
|
358
|
+
@radio_unchecked.checked?.should be_true
|
359
|
+
end
|
360
|
+
end
|
361
|
+
# uncheck!
|
362
|
+
describe '#uncheck!' do
|
363
|
+
before :each do
|
364
|
+
browser.url = fixture('forms_with_input_elements.html')
|
365
|
+
@checkbox_checked = window.find_by_id('new_user_interests_books').first
|
366
|
+
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'unchecks a checkbox' do
|
370
|
+
@checkbox_checked.uncheck!
|
371
|
+
@checkbox_checked.checked?.should be_false
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'cannot uncheck a radio button' do
|
375
|
+
@radio_checked.uncheck!.should raise_error
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
# toggle_check!
|
380
|
+
describe '#toggle_check!' do
|
381
|
+
before :each do
|
382
|
+
browser.url = fixture('forms_with_input_elements.html')
|
383
|
+
@checkbox_checked = window.find_by_id('new_user_interests_books').first
|
384
|
+
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'toggles a checkbox' do
|
388
|
+
@checkbox_checked.toggle_check!
|
389
|
+
@checkbox_checked.checked?.should be_false
|
390
|
+
@checkbox_checked.toggle_check!
|
391
|
+
@checkbox_checked.checked?.should be_true
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'does not appear on a radio button' do
|
395
|
+
@radio_checked.should_not respond_to :toggle_check!
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
# enable!
|
400
|
+
describe '#enable!' do
|
401
|
+
it 'enables a form element' do
|
402
|
+
window.url = fixture('forms_with_input_elements.html')
|
403
|
+
disabled = window.find_by_id('new_user_species').first
|
404
|
+
disabled.enabled?.should be_false
|
405
|
+
disabled.enable!
|
406
|
+
disabled.enabled?.should be_true
|
407
|
+
end
|
408
|
+
end
|
409
|
+
# disable!
|
410
|
+
describe '#disable!' do
|
411
|
+
it 'disables a form element' do
|
412
|
+
window.url = fixture('forms_with_input_elements.html')
|
413
|
+
disabled = window.find_by_id('new_user_email').first
|
414
|
+
disabled.enabled?.should be_true
|
415
|
+
disabled.disable!
|
416
|
+
disabled.enabled?.should be_false
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
# show!
|
421
|
+
describe '#show!' do
|
422
|
+
it 'makes the element visible' do
|
423
|
+
hidden = window.find_by_id('hidden').first
|
424
|
+
hidden.visible?.should be_false
|
425
|
+
hidden.show!
|
426
|
+
hidden.visible?.should be_true
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
# hide!
|
431
|
+
describe '#hide!' do
|
432
|
+
it 'sets the element to display:none' do
|
433
|
+
@element.visible?.should be_true
|
434
|
+
hidden.hide!
|
435
|
+
hidden.visible?.should be_false
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
describe '#trigger!' do
|
440
|
+
it 'fires the given event on the element' do
|
441
|
+
window.find_by_id('link_3').first.trigger!('click')
|
442
|
+
browser.url.should include 'forms_with_input_elements.html'
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'fires event handlers' do
|
446
|
+
window.find_by_id('html_test').first.trigger!('dblclick')
|
447
|
+
window.find_by_id('messages').first.text.should include 'double clicked'
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
# attributes
|
452
|
+
# ----------
|
453
|
+
|
454
|
+
# style
|
455
|
+
|
456
|
+
end
|