watir-formhandler 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -7
- data/lib/watir-formhandler/container.rb +21 -2
- data/spec/container_spec.rb +159 -28
- metadata +2 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e4b363f3156b19ab9d61c9fb72b1f3694b1cab
|
4
|
+
data.tar.gz: 21add3a253b471a36b37b7e6bf2fa2bed1b0de42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450eeb218b9120a69530ace025fe25951f2037cccd6483c2ba4e625096109e7af12cf31c39add13cb765bdcfe43a09de6619fb43f16c0084bba46fc6dc9e5f95
|
7
|
+
data.tar.gz: e08264e4cb7a1d32aa9eae54b6d78a55c6c8fbfe467d44f4a75c914f1e18211f3deb0360e75dbdcbb5d2bebfaae6875ba08efa7132e263e6d0ee23be450d7b47
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@ Extends some Watir classes to provide a more comfortale handling for forms and t
|
|
14
14
|
* [#field_value](#field_value)
|
15
15
|
* [#field](#field)
|
16
16
|
* [#fill_in](#fill_in)
|
17
|
+
* [#value_of](#value_of)
|
17
18
|
* [OptionGroup](#optiongroup)
|
18
19
|
* [:start_node](#start_node)
|
19
20
|
* [Latest Changes](#latest-changes)
|
@@ -64,7 +65,7 @@ currently set value. But be prudent, the data type may vary, just like the custo
|
|
64
65
|
|
65
66
|
### #field
|
66
67
|
|
67
|
-
All Containers now have a method to determine a form field by
|
68
|
+
All Containers now have a method to determine a form field by its label, placeholders or ID,
|
68
69
|
returning the appropriate Watir sub-type class.
|
69
70
|
|
70
71
|
browser = Watir::Browser.new('example_site')
|
@@ -78,7 +79,8 @@ returning the appropriate Watir sub-type class.
|
|
78
79
|
|
79
80
|
### #fill_in
|
80
81
|
|
81
|
-
All Containers now have a method to search a form field by its
|
82
|
+
All Containers now have a method to search a form field by its label, placeholder or ID and
|
83
|
+
change its value.
|
82
84
|
|
83
85
|
browser = Watir::Browser.new('example_site')
|
84
86
|
form = browser.form(id: 'my_form')
|
@@ -90,6 +92,20 @@ All Containers now have a method to search a form field by its name or label and
|
|
90
92
|
# TextField with placeholder
|
91
93
|
# 'Some Text Field'
|
92
94
|
|
95
|
+
### #value_of
|
96
|
+
|
97
|
+
All Containers now have a method to search a form field by its label, placeholder or ID and return
|
98
|
+
its current value.
|
99
|
+
|
100
|
+
browser = Watir::Browser.new('example_site')
|
101
|
+
form = browser.form(id: 'my_form')
|
102
|
+
|
103
|
+
form.read_field('Some Text Field') # Reads the value of field labeled
|
104
|
+
# 'Some Text Field'
|
105
|
+
|
106
|
+
form.fill_in('Some Text Field', placeholder: true) # Reads the value of a TextField with
|
107
|
+
# placeholder 'Some Text Field'
|
108
|
+
|
93
109
|
|
94
110
|
### OptionGroup
|
95
111
|
|
@@ -111,16 +127,27 @@ for these kind of groups, if the respective options has been activated.
|
|
111
127
|
|
112
128
|
### :start_node
|
113
129
|
|
114
|
-
The
|
115
|
-
given String on the Container on which it is called, by default. However, you may specify
|
116
|
-
arbitrary _start_node_ from which to start, which will probably be most useful when calling the
|
130
|
+
The methods _#field_, _#fill_in_ and _#value_of_ will start their search for the specified label
|
131
|
+
with the given String on the Container on which it is called, by default. However, you may specify
|
132
|
+
an arbitrary _start_node_ from which to start, which will probably be most useful when calling the
|
117
133
|
methods directly on your Watir::Browser instance.
|
118
134
|
|
119
|
-
|
120
|
-
|
135
|
+
---
|
136
|
+
|
137
|
+
---
|
121
138
|
|
122
139
|
### Latest Changes
|
123
140
|
|
141
|
+
#### Version 2.6.0
|
142
|
+
|
143
|
+
* Added #value_of method that works in the exact same way as #fill_in, but which returns the
|
144
|
+
current value of a field.
|
145
|
+
|
146
|
+
#### Version 2.5.0
|
147
|
+
|
148
|
+
* Added option to find input fields by ID
|
149
|
+
* Added option to fill input fields by ID
|
150
|
+
|
124
151
|
#### Version 2.4.0
|
125
152
|
|
126
153
|
* Renamed the files in such a way that the gem can now properly required with a hyphen like the
|
@@ -27,13 +27,13 @@ module Watir
|
|
27
27
|
# Fills in the given value(s) to the passed attribute. It therefore accepts the same parameters
|
28
28
|
# as the #field method.
|
29
29
|
# @param [String, Watir::Label] label the label for which to find the form field.
|
30
|
-
# @param [Watir::Element] start_node the node where to start searching for the label.
|
31
30
|
# @param [String, Boolean, Array] value to be set.
|
31
|
+
# @param [Watir::Element] start_node the node where to start searching for the label.
|
32
32
|
# @param [Boolean] include_groups whether to detect the group of a given label.
|
33
33
|
# @param [Boolean] placeholder whether to handle label as Watir::Label or as placeholder
|
34
34
|
# attribute for an input field.
|
35
35
|
# @param [Boolean] id assumes the given label is an HTML ID and searches for it.
|
36
|
-
def fill_in(label, value, start_node: nil, include_groups:
|
36
|
+
def fill_in(label, value, start_node: nil, include_groups: false, placeholder: false, id: false)
|
37
37
|
field(label,
|
38
38
|
start_node: start_node,
|
39
39
|
include_groups: include_groups,
|
@@ -43,6 +43,25 @@ module Watir
|
|
43
43
|
end
|
44
44
|
|
45
45
|
|
46
|
+
# Returns the current value of the specified form field. It therefore accepts the same
|
47
|
+
# parameters as the #field method.
|
48
|
+
# @param [String, Watir::Label] label the label for which to find the form field.
|
49
|
+
# @param [Watir::Element] start_node the node where to start searching for the label.
|
50
|
+
# @param [Boolean] include_groups whether to detect the group of a given label.
|
51
|
+
# @param [Boolean] placeholder whether to handle label as Watir::Label or as placeholder
|
52
|
+
# attribute for an input field.
|
53
|
+
# @param [Boolean] id assumes the given label is an HTML ID and searches for it.
|
54
|
+
# @return [String, Boolean, Array] current value of the field.
|
55
|
+
def value_of(label, start_node: nil, include_groups: false, placeholder: false, id: false)
|
56
|
+
field(label,
|
57
|
+
start_node: start_node,
|
58
|
+
include_groups: include_groups,
|
59
|
+
placeholder: placeholder,
|
60
|
+
id: id
|
61
|
+
).field_value
|
62
|
+
end
|
63
|
+
|
64
|
+
|
46
65
|
# Returns an OptionGroup
|
47
66
|
# @return [OptionGroup] the selected OptionGroup
|
48
67
|
def option_group(*args)
|
data/spec/container_spec.rb
CHANGED
@@ -139,6 +139,7 @@ module Watir
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end # #field
|
142
|
+
################################################################################################
|
142
143
|
|
143
144
|
|
144
145
|
describe '#fill_in' do
|
@@ -175,85 +176,82 @@ module Watir
|
|
175
176
|
end
|
176
177
|
|
177
178
|
it 'fills a Watir::Select with multiple select' do
|
178
|
-
|
179
|
+
options = %w(Option2 Option3)
|
180
|
+
browser.fill_in('Multi Select', options)
|
179
181
|
multiselect = browser.select(id: 'multiselect')
|
180
182
|
expect(multiselect.selected_options.count).to eq(2)
|
181
|
-
expect(multiselect.selected_options.map(&:text)).to eq(
|
183
|
+
expect(multiselect.selected_options.map(&:text)).to eq(options)
|
182
184
|
end
|
183
185
|
|
184
186
|
it 'fills a Watir::OptionGroup' do
|
185
|
-
|
187
|
+
options = %w(Checkbox5 Radio7)
|
188
|
+
browser.fill_in('Checkbox5', options, include_groups: true)
|
186
189
|
option_group = browser.option_group(id: 'radio_and_checkbox')
|
187
190
|
expect(option_group.selected_options.count).to eq(2)
|
188
|
-
expect(option_group.selected_options).to eq(
|
191
|
+
expect(option_group.selected_options).to eq(options)
|
189
192
|
end
|
190
193
|
end # desribe: without a start node
|
191
194
|
|
192
195
|
|
193
196
|
describe 'with a start node' do
|
197
|
+
before(:all){ @browser.refresh }
|
194
198
|
let(:start_node){ browser.element(id: 'main_content') }
|
195
199
|
|
196
200
|
it 'fills a Watir::Checkbox from start node' do
|
197
|
-
|
198
|
-
expect(start_node).to receive(:label)
|
201
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Checkbox'))
|
199
202
|
browser.fill_in('Checkbox', true, start_node: start_node)
|
200
203
|
expect(browser.checkboxes.first).to be_checked
|
201
204
|
end
|
202
205
|
|
203
206
|
it 'fills a Watir::Radio from start node' do
|
204
|
-
|
205
|
-
expect(start_node).to receive(:label)
|
207
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Radio'))
|
206
208
|
browser.fill_in('Radio', true, start_node: start_node)
|
207
209
|
expect(browser.radios.first).to be_checked
|
208
210
|
end
|
209
211
|
|
210
212
|
it 'fills a Watir::Select with single select from start node' do
|
211
|
-
|
212
|
-
expect(start_node).to receive(:label)
|
213
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Select'))
|
213
214
|
browser.fill_in('Select', 'Test2', start_node: start_node)
|
214
215
|
expect(browser.selects.first.selected_options.count).to eq(1)
|
215
216
|
expect(browser.selects.first.selected_options.first.text).to eq('Test2')
|
216
217
|
end
|
217
218
|
|
218
219
|
it 'fills a Watir::Select with multiple select from start node' do
|
219
|
-
|
220
|
-
expect(start_node).to receive(:label)
|
221
|
-
browser.fill_in('Multi Select',
|
220
|
+
options = %w(Option2 Option3)
|
221
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Multi Select'))
|
222
|
+
browser.fill_in('Multi Select', options, start_node: start_node)
|
223
|
+
|
222
224
|
multiselect = browser.select(id: 'multiselect')
|
223
225
|
expect(multiselect.selected_options.count).to eq(2)
|
224
|
-
expect(multiselect.selected_options.map(&:text)).to eq(
|
226
|
+
expect(multiselect.selected_options.map(&:text)).to eq(options)
|
225
227
|
end
|
226
228
|
|
227
229
|
it 'fills a Watir::TextField from start node' do
|
228
|
-
|
229
|
-
expect(start_node).to receive(:label)
|
230
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Text Field'))
|
230
231
|
browser.fill_in('Text Field', 'test text', start_node: start_node)
|
231
232
|
expect(browser.text_fields.first.value).to eq('test text')
|
232
233
|
end
|
233
234
|
|
234
235
|
it 'fills a Watir::TextArea from start node' do
|
235
|
-
|
236
|
-
expect(start_node).to receive(:label)
|
236
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Text Area'))
|
237
237
|
browser.fill_in('Text Area', 'test text', start_node: start_node)
|
238
238
|
expect(browser.textareas.first.value).to eq('test text')
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'fills a Watir::FileField from start node' do
|
242
|
-
|
243
|
-
expect(start_node).to receive(:label)
|
242
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'File'))
|
244
243
|
browser.fill_in('File', File.join(HTML_DIR, FORM_PAGE), start_node: start_node)
|
245
244
|
expect(browser.file_fields.first.value).to eq(FORM_PAGE)
|
246
245
|
end
|
247
246
|
|
248
247
|
it 'fills a Watir::OptionGroup from start node' do
|
249
|
-
|
250
|
-
expect(start_node).to receive(:label)
|
251
|
-
browser.fill_in(
|
252
|
-
|
253
|
-
)
|
248
|
+
options = %w(Checkbox5 Radio7)
|
249
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Checkbox5'))
|
250
|
+
browser.fill_in('Checkbox5', options, include_groups: true, start_node: start_node)
|
251
|
+
|
254
252
|
option_group = browser.option_group(id: 'radio_and_checkbox')
|
255
253
|
expect(option_group.selected_options.count).to eq(2)
|
256
|
-
expect(option_group.selected_options).to eq(
|
254
|
+
expect(option_group.selected_options).to eq(options)
|
257
255
|
end
|
258
256
|
end # descibe: with a start node
|
259
257
|
|
@@ -273,7 +271,7 @@ module Watir
|
|
273
271
|
end# with placeholder: true
|
274
272
|
|
275
273
|
|
276
|
-
describe 'using id: true'
|
274
|
+
describe 'using id: true' do
|
277
275
|
it 'fills field with specified id' do
|
278
276
|
text_id = 'text'
|
279
277
|
browser.fill_in(text_id, 'test', id: true)
|
@@ -281,6 +279,139 @@ module Watir
|
|
281
279
|
end
|
282
280
|
end# using id: true
|
283
281
|
end # #fill_in
|
284
|
-
|
282
|
+
################################################################################################
|
283
|
+
|
284
|
+
|
285
|
+
describe '#value_of' do
|
286
|
+
before(:all){ @browser.refresh }
|
287
|
+
describe 'without a start node' do
|
288
|
+
it 'returns value of Watir::Checkbox' do
|
289
|
+
browser.fill_in('Checkbox', true)
|
290
|
+
expect(browser.value_of('Checkbox')).to be true
|
291
|
+
browser.fill_in('Checkbox', false)
|
292
|
+
expect(browser.value_of('Checkbox')).to be false
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'returns value of Watir::Radio' do
|
296
|
+
browser.fill_in('Radio', true)
|
297
|
+
expect(browser.value_of('Radio')).to be true
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'returns value of Watir::FileField' do
|
301
|
+
browser.fill_in('File', File.join(HTML_DIR, FORM_PAGE))
|
302
|
+
expect(browser.value_of('File')).to eq(FORM_PAGE)
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'returns value of Watir::TextField' do
|
306
|
+
browser.fill_in('Text Field', 'test text')
|
307
|
+
expect(browser.value_of('Text Field')).to eq('test text')
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'returns value of Watir::TextArea' do
|
311
|
+
browser.fill_in('Text Area', 'test text')
|
312
|
+
expect(browser.value_of('Text Area')).to eq('test text')
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'returns value of Watir::Select with single select' do
|
316
|
+
browser.fill_in('Select', 'Test2')
|
317
|
+
expect(browser.value_of('Select')).to eq('Test2')
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'returns value of Watir::Select with multiple select' do
|
321
|
+
target_value = %w(Option2 Option3)
|
322
|
+
browser.fill_in('Multi Select', target_value)
|
323
|
+
expect(browser.value_of('Multi Select')).to eq(%w(Option2 Option3))
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'returns value of Watir::OptionGroup' do
|
327
|
+
options = %w(Checkbox5 Radio7)
|
328
|
+
browser.fill_in('Checkbox5', options, include_groups: true)
|
329
|
+
expect(browser.value_of('Checkbox5', include_groups: true)).to eq(options)
|
330
|
+
end
|
331
|
+
end # desribe: without a start node
|
332
|
+
|
333
|
+
|
334
|
+
describe 'with a start node' do
|
335
|
+
before(:all){ @browser.refresh }
|
336
|
+
let(:start_node){ browser.element(id: 'main_content') }
|
337
|
+
|
338
|
+
it 'returns value of Watir::Checkbox from start node' do
|
339
|
+
browser.fill_in('Checkbox', true, start_node: start_node)
|
340
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Checkbox'))
|
341
|
+
expect(browser.value_of('Checkbox', start_node: start_node)).to be true
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'returns value of Watir::Radio from start node' do
|
345
|
+
browser.fill_in('Radio', true, start_node: start_node)
|
346
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Radio'))
|
347
|
+
expect(browser.value_of('Radio', start_node: start_node)).to be true
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'returns value of Watir::Select with single select from start node' do
|
351
|
+
browser.fill_in('Select', 'Test2', start_node: start_node)
|
352
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Select'))
|
353
|
+
expect(browser.value_of('Select', start_node: start_node)).to eq('Test2')
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'returns value of Watir::Select with multiple select from start node' do
|
357
|
+
options = %w(Option2 Option3)
|
358
|
+
browser.fill_in('Multi Select', options, start_node: start_node)
|
359
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Multi Select'))
|
360
|
+
expect(browser.value_of('Multi Select', start_node: start_node)).to eq(options)
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'returns value of Watir::TextField from start node' do
|
364
|
+
browser.fill_in('Text Field', 'test text', start_node: start_node)
|
365
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Text Field'))
|
366
|
+
expect(browser.value_of('Text Field', start_node: start_node)).to eq('test text')
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'returns value of Watir::TextArea from start node' do
|
370
|
+
browser.fill_in('Text Area', 'test text', start_node: start_node)
|
371
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Text Area'))
|
372
|
+
expect(browser.value_of('Text Area', start_node: start_node)).to eq('test text')
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'returns value of Watir::FileField from start node' do
|
376
|
+
browser.fill_in('File', File.join(HTML_DIR, FORM_PAGE), start_node: start_node)
|
377
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'File'))
|
378
|
+
expect(browser.value_of('File', start_node: start_node)).to eq(FORM_PAGE)
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'returns value of Watir::OptionGroup from start node' do
|
382
|
+
options = %w(Checkbox5 Radio7)
|
383
|
+
browser.fill_in('Checkbox5', options, include_groups: true, start_node: start_node)
|
384
|
+
expect(start_node).to receive(:label).and_return(browser.label(text: 'Checkbox5'))
|
385
|
+
expect(browser.value_of('Checkbox5',
|
386
|
+
start_node: start_node,
|
387
|
+
include_groups: true
|
388
|
+
)
|
389
|
+
).to eq(options)
|
390
|
+
end
|
391
|
+
end # descibe: with a start node
|
392
|
+
|
393
|
+
|
394
|
+
describe 'with placeholder: true' do
|
395
|
+
it 'returns value of Watir::TextField with given text' do
|
396
|
+
browser.fill_in('Placeholder Text', 'Test Text', placeholder: true)
|
397
|
+
expect(browser.value_of('Placeholder Text', placeholder: true)).to eq('Test Text')
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'returns value of Watir::TextArea with given text' do
|
401
|
+
browser.fill_in('Placeholder Area', 'Test Text', placeholder: true)
|
402
|
+
expect(browser.value_of('Placeholder Area', placeholder: true)).to eq('Test Text')
|
403
|
+
end
|
404
|
+
end# with placeholder: true
|
405
|
+
|
406
|
+
|
407
|
+
describe 'using id: true' do
|
408
|
+
it 'returns value of field with specified id' do
|
409
|
+
text_id = 'text'
|
410
|
+
browser.fill_in(text_id, 'test', id: true)
|
411
|
+
expect(browser.value_of(text_id, id: true)).to eq('test')
|
412
|
+
end
|
413
|
+
end# using id: true
|
414
|
+
end
|
415
|
+
end# Container
|
285
416
|
|
286
417
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir-formhandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Komenda
|
@@ -38,9 +38,7 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.11
|
41
|
-
description:
|
42
|
-
Adds some convenience methods to fill out forms in Watir.
|
43
|
-
Latest changes: gem can now be correctly required with >require "watir-formhandler"<
|
41
|
+
description: Adds some convenience methods to fill out forms in Watir.
|
44
42
|
email:
|
45
43
|
- b_d_v@web.de
|
46
44
|
executables: []
|