watir 6.15.0 → 6.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.travis.yml +3 -3
- data/CHANGES.md +8 -0
- data/lib/watir/elements/element.rb +1 -2
- data/lib/watir/elements/select.rb +7 -3
- data/lib/watir/locators/button/selector_builder/xpath.rb +3 -3
- data/lib/watir/locators/element/locator.rb +31 -56
- data/lib/watir/locators/element/selector_builder.rb +29 -63
- data/lib/watir/locators/element/selector_builder/xpath.rb +40 -22
- data/lib/watir/locators/row/selector_builder/xpath.rb +5 -7
- data/lib/watir/locators/text_area/selector_builder/xpath.rb +1 -1
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +1 -1
- data/lib/watir/version.rb +1 -1
- data/lib/watir/wait.rb +5 -5
- data/spec/unit/element_locator_spec.rb +10 -9
- data/spec/watirspec/element_hidden_spec.rb +1 -1
- data/spec/watirspec/elements/dl_spec.rb +3 -3
- data/spec/watirspec/elements/element_spec.rb +1 -13
- data/spec/watirspec/elements/link_spec.rb +1 -1
- data/spec/watirspec/elements/select_list_spec.rb +3 -2
- data/spec/watirspec/elements/text_field_spec.rb +1 -1
- data/spec/watirspec/html/forms_with_input_elements.html +3 -3
- data/spec/watirspec/selector_builder/button_spec.rb +30 -34
- data/spec/watirspec/selector_builder/cell_spec.rb +10 -11
- data/spec/watirspec/selector_builder/element_spec.rb +84 -95
- data/spec/watirspec/selector_builder/row_spec.rb +15 -17
- data/spec/watirspec/selector_builder/text_spec.rb +52 -23
- metadata +2 -2
@@ -10,12 +10,11 @@ describe Watir::Locators::Cell::SelectorBuilder do
|
|
10
10
|
|
11
11
|
@query_scope ||= browser.element(id: 'gregory').locate
|
12
12
|
|
13
|
-
|
14
|
-
expect(built).to eq [@wd_locator, (@remaining || {})]
|
13
|
+
expect(selector_builder.build(@selector)).to eq @built
|
15
14
|
|
16
15
|
next unless @data_locator || @tag_name
|
17
16
|
|
18
|
-
expect { @located = @query_scope.wd.first(@
|
17
|
+
expect { @located = @query_scope.wd.first(@built) }.not_to raise_exception
|
19
18
|
|
20
19
|
if @data_locator
|
21
20
|
expect(@located.attribute('data-locator')).to eq(@data_locator)
|
@@ -29,7 +28,7 @@ describe Watir::Locators::Cell::SelectorBuilder do
|
|
29
28
|
it 'without any arguments' do
|
30
29
|
browser.goto(WatirSpec.url_for('tables.html'))
|
31
30
|
@selector = {}
|
32
|
-
@
|
31
|
+
@built = {xpath: "./*[local-name()='th' or local-name()='td']"}
|
33
32
|
@data_locator = 'first cell'
|
34
33
|
end
|
35
34
|
|
@@ -40,31 +39,31 @@ describe Watir::Locators::Cell::SelectorBuilder do
|
|
40
39
|
|
41
40
|
it 'positive' do
|
42
41
|
@selector = {index: 3}
|
43
|
-
@
|
42
|
+
@built = {xpath: "(./*[local-name()='th' or local-name()='td'])[4]"}
|
44
43
|
@data_locator = 'after tax'
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'negative' do
|
48
47
|
@selector = {index: -3}
|
49
|
-
@
|
48
|
+
@built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()-2]"}
|
50
49
|
@data_locator = 'before tax'
|
51
50
|
end
|
52
51
|
|
53
52
|
it 'last' do
|
54
53
|
@selector = {index: -1}
|
55
|
-
@
|
54
|
+
@built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()]"}
|
56
55
|
@data_locator = 'after tax'
|
57
56
|
end
|
58
57
|
|
59
58
|
it 'does not return index if it is zero' do
|
60
59
|
@selector = {index: 0}
|
61
|
-
@
|
60
|
+
@built = {xpath: "./*[local-name()='th' or local-name()='td']"}
|
62
61
|
@data_locator = 'first cell'
|
63
62
|
end
|
64
63
|
|
65
64
|
it 'raises exception when index is not an Integer', skip_after: true do
|
66
65
|
selector = {index: 'foo'}
|
67
|
-
msg =
|
66
|
+
msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
|
68
67
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
69
68
|
end
|
70
69
|
end
|
@@ -76,7 +75,7 @@ describe Watir::Locators::Cell::SelectorBuilder do
|
|
76
75
|
|
77
76
|
it 'attribute and text' do
|
78
77
|
@selector = {headers: /before_tax/, text: '5 934'}
|
79
|
-
@
|
78
|
+
@built = {xpath: "./*[local-name()='th' or local-name()='td']" \
|
80
79
|
"[normalize-space()='5 934'][contains(@headers, 'before_tax')]"}
|
81
80
|
@data_locator = 'before tax'
|
82
81
|
end
|
@@ -86,7 +85,7 @@ describe Watir::Locators::Cell::SelectorBuilder do
|
|
86
85
|
@query_scope = browser.element(id: 'p3').locate
|
87
86
|
|
88
87
|
@selector = {adjacent: :ancestor, index: 2}
|
89
|
-
@
|
88
|
+
@built = {xpath: './ancestor::*[3]'}
|
90
89
|
@data_locator = 'top table'
|
91
90
|
end
|
92
91
|
end
|
@@ -9,12 +9,11 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
9
9
|
|
10
10
|
@attributes ||= Watir::HTMLElement.attribute_list
|
11
11
|
@query_scope ||= browser
|
12
|
-
|
13
|
-
expect(built).to eq [@wd_locator, (@remaining || {})]
|
12
|
+
expect(selector_builder.build(@selector)).to eq @built
|
14
13
|
|
15
14
|
next unless @data_locator || @tag_name
|
16
15
|
|
17
|
-
expect { @located = @query_scope.wd.first(@
|
16
|
+
expect { @located = @query_scope.wd.first(@built) }.not_to raise_exception
|
18
17
|
|
19
18
|
if @data_locator
|
20
19
|
expect(@located.attribute('data-locator')).to eq(@data_locator)
|
@@ -27,7 +26,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
27
26
|
|
28
27
|
it 'without any arguments' do
|
29
28
|
@selector = {}
|
30
|
-
@
|
29
|
+
@built = {xpath: './/*'}
|
31
30
|
@tag_name = 'html'
|
32
31
|
end
|
33
32
|
|
@@ -38,37 +37,37 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
38
37
|
|
39
38
|
it 'locates with xpath only' do
|
40
39
|
@selector = {xpath: './/div'}
|
41
|
-
@
|
40
|
+
@built = @selector.dup
|
42
41
|
@data_locator = 'first div'
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'locates with css only' do
|
46
45
|
@selector = {css: 'div'}
|
47
|
-
@
|
46
|
+
@built = @selector.dup
|
48
47
|
@data_locator = 'first div'
|
49
48
|
end
|
50
49
|
|
51
|
-
it '
|
52
|
-
selector = {xpath: '
|
53
|
-
|
54
|
-
|
50
|
+
it 'locates when attributes combined with xpath' do
|
51
|
+
@selector = {xpath: './/div', random: 'foo'}
|
52
|
+
@built = @selector.dup
|
53
|
+
@data_locator = 'first div'
|
55
54
|
end
|
56
55
|
|
57
|
-
it '
|
58
|
-
selector = {
|
59
|
-
|
60
|
-
|
56
|
+
it 'locates when attributes combined with css' do
|
57
|
+
@selector = {css: 'div', random: 'foo'}
|
58
|
+
@built = @selector.dup
|
59
|
+
@data_locator = 'first div'
|
61
60
|
end
|
62
61
|
|
63
|
-
it 'raises exception when
|
64
|
-
selector = {
|
65
|
-
msg = 'css cannot be combined
|
62
|
+
it 'raises exception when using xpath & css', skip_after: true do
|
63
|
+
selector = {xpath: './/*', css: 'div'}
|
64
|
+
msg = ':xpath and :css cannot be combined ({:xpath=>".//*", :css=>"div"})'
|
66
65
|
expect { selector_builder.build(selector) }.to raise_exception Watir::Exception::LocatorException, msg
|
67
66
|
end
|
68
67
|
|
69
68
|
it 'raises exception when not a String', skip_after: true do
|
70
69
|
selector = {xpath: 7}
|
71
|
-
msg = /expected String, got 7:(Fixnum|Integer)/
|
70
|
+
msg = /expected one of \[String\], got 7:(Fixnum|Integer)/
|
72
71
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
73
72
|
end
|
74
73
|
|
@@ -96,25 +95,25 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
96
95
|
|
97
96
|
it 'with String equals' do
|
98
97
|
@selector = {tag_name: 'div'}
|
99
|
-
@
|
98
|
+
@built = {xpath: ".//*[local-name()='div']"}
|
100
99
|
@data_locator = 'first div'
|
101
100
|
end
|
102
101
|
|
103
102
|
it 'with simple Regexp contains' do
|
104
103
|
@selector = {tag_name: /div/}
|
105
|
-
@
|
104
|
+
@built = {xpath: ".//*[contains(local-name(), 'div')]"}
|
106
105
|
@data_locator = 'first div'
|
107
106
|
end
|
108
107
|
|
109
108
|
it 'with Symbol' do
|
110
109
|
@selector = {tag_name: :div}
|
111
|
-
@
|
110
|
+
@built = {xpath: ".//*[local-name()='div']"}
|
112
111
|
@data_locator = 'first div'
|
113
112
|
end
|
114
113
|
|
115
114
|
it 'raises exception when not a String or Regexp', skip_after: true do
|
116
115
|
selector = {tag_name: 7}
|
117
|
-
msg = /expected
|
116
|
+
msg = /expected one of \[String, Regexp, Symbol\], got 7:(Fixnum|Integer)/
|
118
117
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
119
118
|
end
|
120
119
|
end
|
@@ -126,63 +125,63 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
126
125
|
|
127
126
|
it 'class_name is converted to class' do
|
128
127
|
@selector = {class_name: 'user'}
|
129
|
-
@
|
128
|
+
@built = {xpath: ".//*[contains(concat(' ', @class, ' '), ' user ')]"}
|
130
129
|
@data_locator = 'form'
|
131
130
|
end
|
132
131
|
|
133
132
|
# TODO: This functionality is deprecated with "class_array"
|
134
133
|
it 'values with spaces' do
|
135
134
|
@selector = {class_name: 'multiple classes here'}
|
136
|
-
@
|
135
|
+
@built = {xpath: ".//*[contains(concat(' ', @class, ' '), ' multiple classes here ')]"}
|
137
136
|
@data_locator = 'first div'
|
138
137
|
end
|
139
138
|
|
140
139
|
it 'single String concatenates' do
|
141
140
|
@selector = {class: 'user'}
|
142
|
-
@
|
141
|
+
@built = {xpath: ".//*[contains(concat(' ', @class, ' '), ' user ')]"}
|
143
142
|
@data_locator = 'form'
|
144
143
|
end
|
145
144
|
|
146
145
|
it 'Array of String concatenates with and' do
|
147
146
|
@selector = {class: %w[multiple here]}
|
148
|
-
@
|
147
|
+
@built = {xpath: ".//*[contains(concat(' ', @class, ' '), ' multiple ') and " \
|
149
148
|
"contains(concat(' ', @class, ' '), ' here ')]"}
|
150
149
|
@data_locator = 'first div'
|
151
150
|
end
|
152
151
|
|
153
152
|
it 'simple Regexp contains' do
|
154
153
|
@selector = {class_name: /use/}
|
155
|
-
@
|
154
|
+
@built = {xpath: ".//*[contains(@class, 'use')]"}
|
156
155
|
@data_locator = 'form'
|
157
156
|
end
|
158
157
|
|
159
158
|
it 'Array of Regexp contains with and' do
|
160
159
|
@selector = {class: [/mult/, /her/]}
|
161
|
-
@
|
160
|
+
@built = {xpath: ".//*[contains(@class, 'mult') and contains(@class, 'her')]"}
|
162
161
|
@data_locator = 'first div'
|
163
162
|
end
|
164
163
|
|
165
164
|
it 'single negated String concatenates with not' do
|
166
165
|
@selector = {class: '!multiple'}
|
167
|
-
@
|
166
|
+
@built = {xpath: ".//*[not(contains(concat(' ', @class, ' '), ' multiple '))]"}
|
168
167
|
@tag_name = 'html'
|
169
168
|
end
|
170
169
|
|
171
170
|
it 'single Boolean true provides the at' do
|
172
171
|
@selector = {class: true}
|
173
|
-
@
|
172
|
+
@built = {xpath: './/*[@class]'}
|
174
173
|
@data_locator = 'first div'
|
175
174
|
end
|
176
175
|
|
177
176
|
it 'single Boolean false provides the not atat' do
|
178
177
|
@selector = {class: false}
|
179
|
-
@
|
178
|
+
@built = {xpath: './/*[not(@class)]'}
|
180
179
|
@tag_name = 'html'
|
181
180
|
end
|
182
181
|
|
183
182
|
it 'Array of mixed String, Regexp and Boolean contains and concatenates with and and not' do
|
184
183
|
@selector = {class: [/mult/, 'classes', '!here']}
|
185
|
-
@
|
184
|
+
@built = {xpath: ".//*[contains(@class, 'mult') and contains(concat(' ', @class, ' '), ' classes ') " \
|
186
185
|
"and not(contains(concat(' ', @class, ' '), ' here '))]"}
|
187
186
|
@data_locator = 'second div'
|
188
187
|
end
|
@@ -195,7 +194,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
195
194
|
|
196
195
|
it 'raises exception when Array values are not a String or Regexp', skip_after: true do
|
197
196
|
selector = {class: [7]}
|
198
|
-
msg = /expected
|
197
|
+
msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:(Fixnum|Integer)/
|
199
198
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
200
199
|
end
|
201
200
|
|
@@ -219,37 +218,37 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
219
218
|
|
220
219
|
it 'with href attribute' do
|
221
220
|
@selector = {href: 'watirspec.css'}
|
222
|
-
@
|
221
|
+
@built = {xpath: ".//*[normalize-space(@href)='watirspec.css']"}
|
223
222
|
@data_locator = 'link'
|
224
223
|
end
|
225
224
|
|
226
225
|
it 'with string attribute' do
|
227
226
|
@selector = {'name' => 'user_new'}
|
228
|
-
@
|
227
|
+
@built = {xpath: ".//*[@name='user_new']"}
|
229
228
|
@data_locator = 'form'
|
230
229
|
end
|
231
230
|
|
232
231
|
it 'with String equals' do
|
233
232
|
@selector = {name: 'user_new'}
|
234
|
-
@
|
233
|
+
@built = {xpath: ".//*[@name='user_new']"}
|
235
234
|
@data_locator = 'form'
|
236
235
|
end
|
237
236
|
|
238
237
|
it 'with TrueClass no equals' do
|
239
238
|
@selector = {tag_name: 'input', name: true}
|
240
|
-
@
|
239
|
+
@built = {xpath: ".//*[local-name()='input'][@name]"}
|
241
240
|
@data_locator = 'input name'
|
242
241
|
end
|
243
242
|
|
244
243
|
it 'with FalseClass not with no equals' do
|
245
244
|
@selector = {tag_name: 'input', name: false}
|
246
|
-
@
|
245
|
+
@built = {xpath: ".//*[local-name()='input'][not(@name)]"}
|
247
246
|
@data_locator = 'input nameless'
|
248
247
|
end
|
249
248
|
|
250
249
|
it 'with multiple attributes: no equals and not with no equals and equals' do
|
251
250
|
@selector = {readonly: true, foo: false, id: 'good_luck'}
|
252
|
-
@
|
251
|
+
@built = {xpath: ".//*[@readonly and not(@foo) and @id='good_luck']"}
|
253
252
|
@data_locator = 'Good Luck'
|
254
253
|
end
|
255
254
|
|
@@ -273,13 +272,13 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
273
272
|
|
274
273
|
it 'with Regexp' do
|
275
274
|
@selector = {name: /user/}
|
276
|
-
@
|
275
|
+
@built = {xpath: ".//*[contains(@name, 'user')]"}
|
277
276
|
@data_locator = 'form'
|
278
277
|
end
|
279
278
|
|
280
279
|
it 'with multiple Regexp attributes separated by and' do
|
281
280
|
@selector = {readonly: /read/, id: /good/}
|
282
|
-
@
|
281
|
+
@built = {xpath: ".//*[contains(@readonly, 'read') and contains(@id, 'good')]"}
|
283
282
|
@data_locator = 'Good Luck'
|
284
283
|
end
|
285
284
|
end
|
@@ -291,20 +290,20 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
291
290
|
|
292
291
|
it 'String uses normalize space equals' do
|
293
292
|
@selector = {text: 'Add user'}
|
294
|
-
@
|
293
|
+
@built = {xpath: ".//*[normalize-space()='Add user']"}
|
295
294
|
@data_locator = 'add user'
|
296
295
|
end
|
297
296
|
|
298
297
|
# Deprecated with :caption
|
299
298
|
it 'with caption attribute' do
|
300
299
|
@selector = {caption: 'Add user'}
|
301
|
-
@
|
300
|
+
@built = {xpath: ".//*[normalize-space()='Add user']"}
|
302
301
|
@data_locator = 'add user'
|
303
302
|
end
|
304
303
|
|
305
304
|
it 'raises exception when text is not a String or Regexp', skip_after: true do
|
306
305
|
selector = {text: 7}
|
307
|
-
msg = /expected
|
306
|
+
msg = /expected one of \[String, Regexp\], got 7:(Fixnum|Integer)/
|
308
307
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
309
308
|
end
|
310
309
|
end
|
@@ -316,30 +315,30 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
316
315
|
|
317
316
|
it 'positive' do
|
318
317
|
@selector = {tag_name: 'div', index: 7}
|
319
|
-
@
|
318
|
+
@built = {xpath: "(.//*[local-name()='div'])[8]"}
|
320
319
|
@data_locator = 'content'
|
321
320
|
end
|
322
321
|
|
323
322
|
it 'negative' do
|
324
323
|
@selector = {tag_name: 'div', index: -7}
|
325
|
-
@
|
324
|
+
@built = {xpath: "(.//*[local-name()='div'])[last()-6]"}
|
326
325
|
@data_locator = 'second div'
|
327
326
|
end
|
328
327
|
|
329
328
|
it 'last' do
|
330
329
|
@selector = {tag_name: 'div', index: -1}
|
331
|
-
@
|
330
|
+
@built = {xpath: "(.//*[local-name()='div'])[last()]"}
|
332
331
|
@data_locator = 'content'
|
333
332
|
end
|
334
333
|
|
335
334
|
it 'does not return index if it is zero' do
|
336
335
|
@selector = {tag_name: 'div', index: 0}
|
337
|
-
@
|
336
|
+
@built = {xpath: ".//*[local-name()='div']"}
|
338
337
|
end
|
339
338
|
|
340
339
|
it 'raises exception when index is not an Integer', skip_after: true do
|
341
340
|
selector = {index: 'foo'}
|
342
|
-
msg =
|
341
|
+
msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
|
343
342
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
344
343
|
end
|
345
344
|
end
|
@@ -351,8 +350,8 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
351
350
|
|
352
351
|
it 'locates the element associated with the label element located by the text of the provided label key' do
|
353
352
|
@selector = {label: 'Cars'}
|
354
|
-
@
|
355
|
-
"or parent::label[normalize-space()='Cars']
|
353
|
+
@built = {xpath: ".//*[@id=//label[normalize-space()='Cars']/@for "\
|
354
|
+
"or parent::label[normalize-space()='Cars']]"}
|
356
355
|
@data_locator = 'cars'
|
357
356
|
end
|
358
357
|
|
@@ -360,7 +359,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
360
359
|
@attributes ||= Watir::Option.attribute_list
|
361
360
|
|
362
361
|
@selector = {tag_name: 'option', label: 'Germany'}
|
363
|
-
@
|
362
|
+
@built = {xpath: ".//*[local-name()='option'][@label='Germany']"}
|
364
363
|
@data_locator = 'Berliner'
|
365
364
|
end
|
366
365
|
end
|
@@ -372,7 +371,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
372
371
|
|
373
372
|
it 'raises exception when not a Symbol', skip_after: true do
|
374
373
|
selector = {adjacent: 'foo', index: 0}
|
375
|
-
msg = 'expected Symbol, got "foo":String'
|
374
|
+
msg = 'expected one of [Symbol], got "foo":String'
|
376
375
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
377
376
|
end
|
378
377
|
|
@@ -386,21 +385,21 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
386
385
|
it 'with no other arguments' do
|
387
386
|
@query_scope = browser.div(id: 'first_sibling')
|
388
387
|
@selector = {adjacent: :ancestor, index: 0}
|
389
|
-
@
|
388
|
+
@built = {xpath: './ancestor::*[1]'}
|
390
389
|
@data_locator = 'parent'
|
391
390
|
end
|
392
391
|
|
393
392
|
it 'with index' do
|
394
393
|
@query_scope = browser.div(id: 'first_sibling')
|
395
394
|
@selector = {adjacent: :ancestor, index: 2}
|
396
|
-
@
|
395
|
+
@built = {xpath: './ancestor::*[3]'}
|
397
396
|
@data_locator = 'grandparent'
|
398
397
|
end
|
399
398
|
|
400
399
|
it 'with multiple locators' do
|
401
400
|
@query_scope = browser.div(id: 'first_sibling')
|
402
401
|
@selector = {adjacent: :ancestor, id: true, tag_name: 'div', class: 'ancestor', index: 1}
|
403
|
-
@
|
402
|
+
@built = {xpath: "./ancestor::*[local-name()='div']"\
|
404
403
|
"[contains(concat(' ', @class, ' '), ' ancestor ')][@id][2]"}
|
405
404
|
@data_locator = 'grandparent'
|
406
405
|
end
|
@@ -417,21 +416,21 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
417
416
|
it 'with no other arguments' do
|
418
417
|
@query_scope = browser.div(id: 'first_sibling')
|
419
418
|
@selector = {adjacent: :following, index: 0}
|
420
|
-
@
|
419
|
+
@built = {xpath: './following-sibling::*[1]'}
|
421
420
|
@data_locator = 'between_siblings1'
|
422
421
|
end
|
423
422
|
|
424
423
|
it 'with index' do
|
425
424
|
@query_scope = browser.div(id: 'first_sibling')
|
426
425
|
@selector = {adjacent: :following, index: 2}
|
427
|
-
@
|
426
|
+
@built = {xpath: './following-sibling::*[3]'}
|
428
427
|
@data_locator = 'between_siblings2'
|
429
428
|
end
|
430
429
|
|
431
430
|
it 'with multiple locators' do
|
432
431
|
@query_scope = browser.div(id: 'first_sibling')
|
433
432
|
@selector = {adjacent: :following, tag_name: 'div', class: 'b', index: 0, id: true}
|
434
|
-
@
|
433
|
+
@built = {xpath: "./following-sibling::*[local-name()='div']"\
|
435
434
|
"[contains(concat(' ', @class, ' '), ' b ')][@id][1]"}
|
436
435
|
@data_locator = 'second_sibling'
|
437
436
|
end
|
@@ -439,7 +438,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
439
438
|
it 'with text' do
|
440
439
|
@query_scope = browser.div(id: 'first_sibling')
|
441
440
|
@selector = {adjacent: :following, text: 'Third', index: 0}
|
442
|
-
@
|
441
|
+
@built = {xpath: "./following-sibling::*[normalize-space()='Third'][1]"}
|
443
442
|
@data_locator = 'third_sibling'
|
444
443
|
end
|
445
444
|
end
|
@@ -448,21 +447,21 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
448
447
|
it 'with no other arguments' do
|
449
448
|
@query_scope = browser.div(id: 'third_sibling')
|
450
449
|
@selector = {adjacent: :preceding, index: 0}
|
451
|
-
@
|
450
|
+
@built = {xpath: './preceding-sibling::*[1]'}
|
452
451
|
@data_locator = 'between_siblings2'
|
453
452
|
end
|
454
453
|
|
455
454
|
it 'with index' do
|
456
455
|
@query_scope = browser.div(id: 'third_sibling')
|
457
456
|
@selector = {adjacent: :preceding, index: 2}
|
458
|
-
@
|
457
|
+
@built = {xpath: './preceding-sibling::*[3]'}
|
459
458
|
@data_locator = 'between_siblings1'
|
460
459
|
end
|
461
460
|
|
462
461
|
it 'with multiple locators' do
|
463
462
|
@query_scope = browser.div(id: 'third_sibling')
|
464
463
|
@selector = {adjacent: :preceding, tag_name: 'div', class: 'b', id: true, index: 0}
|
465
|
-
@
|
464
|
+
@built = {xpath: "./preceding-sibling::*[local-name()='div']"\
|
466
465
|
"[contains(concat(' ', @class, ' '), ' b ')][@id][1]"}
|
467
466
|
@data_locator = 'second_sibling'
|
468
467
|
end
|
@@ -470,7 +469,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
470
469
|
it 'with text' do
|
471
470
|
@query_scope = browser.div(id: 'third_sibling')
|
472
471
|
@selector = {adjacent: :preceding, text: 'Second', index: 0}
|
473
|
-
@
|
472
|
+
@built = {xpath: "./preceding-sibling::*[normalize-space()='Second'][1]"}
|
474
473
|
@data_locator = 'second_sibling'
|
475
474
|
end
|
476
475
|
end
|
@@ -479,21 +478,21 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
479
478
|
it 'with no other arguments' do
|
480
479
|
@query_scope = browser.div(id: 'first_sibling')
|
481
480
|
@selector = {adjacent: :child, index: 0}
|
482
|
-
@
|
481
|
+
@built = {xpath: './child::*[1]'}
|
483
482
|
@data_locator = 'child span'
|
484
483
|
end
|
485
484
|
|
486
485
|
it 'with index' do
|
487
486
|
@query_scope = browser.div(id: 'parent')
|
488
487
|
@selector = {adjacent: :child, index: 2}
|
489
|
-
@
|
488
|
+
@built = {xpath: './child::*[3]'}
|
490
489
|
@data_locator = 'second_sibling'
|
491
490
|
end
|
492
491
|
|
493
492
|
it 'with multiple locators' do
|
494
493
|
@query_scope = browser.div(id: 'parent')
|
495
494
|
@selector = {adjacent: :child, tag_name: 'div', class: 'b', id: true, index: 0}
|
496
|
-
@
|
495
|
+
@built = {xpath: "./child::*[local-name()='div']"\
|
497
496
|
"[contains(concat(' ', @class, ' '), ' b ')][@id][1]"}
|
498
497
|
@data_locator = 'second_sibling'
|
499
498
|
end
|
@@ -501,7 +500,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
501
500
|
it 'with text' do
|
502
501
|
@query_scope = browser.div(id: 'parent')
|
503
502
|
@selector = {adjacent: :child, text: 'Second', index: 0}
|
504
|
-
@
|
503
|
+
@built = {xpath: "./child::*[normalize-space()='Second'][1]"}
|
505
504
|
@data_locator = 'second_sibling'
|
506
505
|
end
|
507
506
|
end
|
@@ -514,7 +513,7 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
514
513
|
|
515
514
|
it 'locates using tag name, class, attributes and text' do
|
516
515
|
@selector = {tag_name: 'div', class: 'content', contenteditable: 'true', text: 'Foo'}
|
517
|
-
@
|
516
|
+
@built = {xpath: ".//*[local-name()='div'][contains(concat(' ', @class, ' '), ' content ')]" \
|
518
517
|
"[normalize-space()='Foo'][@contenteditable='true']"}
|
519
518
|
@data_locator = 'content'
|
520
519
|
end
|
@@ -527,13 +526,13 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
527
526
|
|
528
527
|
it 'handles spaces' do
|
529
528
|
@selector = {title: /od Lu/}
|
530
|
-
@
|
529
|
+
@built = {xpath: ".//*[contains(@title, 'od Lu')]"}
|
531
530
|
@data_locator = 'Good Luck'
|
532
531
|
end
|
533
532
|
|
534
533
|
it 'handles escaped characters' do
|
535
534
|
@selector = {src: /ages\/but/}
|
536
|
-
@
|
535
|
+
@built = {xpath: ".//*[contains(@src, 'ages/but')]"}
|
537
536
|
@data_locator = 'submittable button'
|
538
537
|
end
|
539
538
|
end
|
@@ -545,40 +544,36 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
545
544
|
|
546
545
|
it 'handles wildcards' do
|
547
546
|
@selector = {src: /ages.*but/}
|
548
|
-
@
|
547
|
+
@built = {xpath: ".//*[contains(@src, 'ages') and contains(@src, 'but')]", src: /ages.*but/}
|
549
548
|
@data_locator = 'submittable button'
|
550
|
-
@remaining = {src: /ages.*but/}
|
551
549
|
end
|
552
550
|
|
553
551
|
it 'handles optional characters' do
|
554
552
|
@selector = {src: /ages ?but/}
|
555
|
-
@
|
553
|
+
@built = {xpath: ".//*[contains(@src, 'ages') and contains(@src, 'but')]", src: /ages ?but/}
|
556
554
|
@data_locator = 'submittable button'
|
557
|
-
@remaining = {src: /ages ?but/}
|
558
555
|
end
|
559
556
|
|
560
557
|
it 'handles anchors' do
|
561
558
|
@selector = {name: /^new_user_image$/}
|
562
|
-
@
|
559
|
+
@built = {xpath: ".//*[contains(@name, 'new_user_image')]", name: /^new_user_image$/}
|
563
560
|
@data_locator = 'submittable button'
|
564
|
-
@remaining = {name: /^new_user_image$/}
|
565
561
|
end
|
566
562
|
|
567
563
|
it 'handles beginning anchor' do
|
568
564
|
@selector = {src: /^i/}
|
569
|
-
@
|
565
|
+
@built = {xpath: ".//*[starts-with(@src, 'i')]"}
|
570
566
|
@data_locator = 'submittable button'
|
571
567
|
end
|
572
568
|
|
573
569
|
it 'does not use starts-with if visible locator used' do
|
574
570
|
@selector = {id: /^vis/, visible_text: 'shown div'}
|
575
|
-
@
|
576
|
-
@remaining = {id: /^vis/, visible_text: 'shown div'}
|
571
|
+
@built = {xpath: ".//*[contains(@id, 'vis')]", id: /^vis/, visible_text: 'shown div'}
|
577
572
|
end
|
578
573
|
|
579
574
|
it 'handles case insensitive' do
|
580
575
|
@selector = {action: /me/i}
|
581
|
-
@
|
576
|
+
@built = {xpath: './/*[contains(translate(@action,' \
|
582
577
|
"'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \
|
583
578
|
"'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'), 'me')]"}
|
584
579
|
@data_locator = 'form'
|
@@ -589,49 +584,43 @@ describe Watir::Locators::Element::SelectorBuilder do
|
|
589
584
|
context 'returns locators that can not be directly translated' do
|
590
585
|
it 'attribute with complicated Regexp at end' do
|
591
586
|
@selector = {action: /me$/}
|
592
|
-
@
|
593
|
-
@remaining = {action: /me$/}
|
587
|
+
@built = {xpath: ".//*[contains(@action, 'me')]", action: /me$/}
|
594
588
|
end
|
595
589
|
|
596
590
|
it 'class with complicated Regexp' do
|
597
591
|
@selector = {class: /he?r/}
|
598
|
-
@
|
599
|
-
@remaining = {class: [/he?r/]}
|
592
|
+
@built = {xpath: ".//*[contains(@class, 'h') and contains(@class, 'r')]", class: [/he?r/]}
|
600
593
|
end
|
601
594
|
|
602
595
|
it 'text with any Regexp' do
|
603
596
|
@selector = {text: /Add/}
|
604
|
-
@
|
605
|
-
@remaining = {text: /Add/}
|
597
|
+
@built = {xpath: './/*', text: /Add/}
|
606
598
|
end
|
607
599
|
|
608
600
|
it 'visible' do
|
609
601
|
@selector = {tag_name: 'div', visible: true}
|
610
|
-
@
|
611
|
-
@remaining = {visible: true}
|
602
|
+
@built = {xpath: ".//*[local-name()='div']", visible: true}
|
612
603
|
end
|
613
604
|
|
614
605
|
it 'not visible' do
|
615
606
|
@selector = {tag_name: 'span', visible: false}
|
616
|
-
@
|
617
|
-
@remaining = {visible: false}
|
607
|
+
@built = {xpath: ".//*[local-name()='span']", visible: false}
|
618
608
|
end
|
619
609
|
|
620
610
|
it 'visible text' do
|
621
611
|
@selector = {tag_name: 'span', visible_text: 'foo'}
|
622
|
-
@
|
623
|
-
@remaining = {visible_text: 'foo'}
|
612
|
+
@built = {xpath: ".//*[local-name()='span']", visible_text: 'foo'}
|
624
613
|
end
|
625
614
|
|
626
615
|
it 'raises exception when visible is not boolean', skip_after: true do
|
627
616
|
selector = {visible: 'foo'}
|
628
|
-
msg = 'expected
|
617
|
+
msg = 'expected one of [TrueClass, FalseClass], got "foo":String'
|
629
618
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
630
619
|
end
|
631
620
|
|
632
621
|
it 'raises exception when visible text is not a String or Regexp', skip_after: true do
|
633
622
|
selector = {visible_text: 7}
|
634
|
-
msg = /expected
|
623
|
+
msg = /expected one of \[String, Regexp\], got 7:(Fixnum|Integer)/
|
635
624
|
expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
|
636
625
|
end
|
637
626
|
end
|