watir 7.2.0 → 7.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/chrome.yml +1 -1
- data/.github/workflows/edge.yml +1 -1
- data/.github/workflows/firefox.yml +1 -1
- data/.github/workflows/ie.yml +1 -1
- data/.github/workflows/safari.yml +1 -1
- data/.github/workflows/unit.yml +1 -1
- data/.rubocop.yml +25 -12
- data/.rubocop_todo.yml +8 -1
- data/CHANGES.md +6 -1
- data/LICENSE +2 -2
- data/lib/watir/capabilities.rb +1 -1
- data/lib/watir/locators/anchor/selector_builder.rb +3 -0
- data/lib/watir/locators/element/matcher.rb +2 -1
- data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
- data/lib/watir/locators/text_field/matcher.rb +0 -4
- data/lib/watir/version.rb +1 -1
- data/spec/locator_spec_helper.rb +0 -8
- data/spec/unit/capabilities_spec.rb +553 -561
- data/spec/unit/element_locator_spec.rb +89 -78
- data/spec/unit/match_elements/button_spec.rb +69 -62
- data/spec/unit/match_elements/element_spec.rb +303 -309
- data/spec/unit/match_elements/text_field_spec.rb +76 -73
- data/spec/unit/selector_builder/anchor_spec.rb +39 -33
- data/spec/unit/selector_builder/button_spec.rb +209 -202
- data/spec/unit/selector_builder/cell_spec.rb +48 -42
- data/spec/unit/selector_builder/element_spec.rb +634 -627
- data/spec/unit/selector_builder/row_spec.rb +119 -113
- data/spec/unit/selector_builder/text_field_spec.rb +195 -188
- data/spec/unit/selector_builder/textarea_spec.rb +22 -14
- data/spec/unit/wait_spec.rb +85 -81
- data/spec/watirspec/adjacent_spec.rb +249 -247
- data/spec/watirspec/after_hooks_spec.rb +161 -159
- data/spec/watirspec/alert_spec.rb +61 -58
- data/spec/watirspec/browser_spec.rb +409 -409
- data/spec/watirspec/capabilities_spec.rb +89 -99
- data/spec/watirspec/cookies_spec.rb +120 -118
- data/spec/watirspec/drag_and_drop_spec.rb +26 -24
- data/spec/watirspec/element_hidden_spec.rb +66 -60
- data/spec/watirspec/elements/area_spec.rb +49 -47
- data/spec/watirspec/elements/areas_spec.rb +27 -25
- data/spec/watirspec/elements/button_spec.rb +253 -251
- data/spec/watirspec/elements/buttons_spec.rb +36 -34
- data/spec/watirspec/elements/checkbox_spec.rb +48 -36
- data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
- data/spec/watirspec/elements/collections_spec.rb +126 -119
- data/spec/watirspec/elements/date_field_spec.rb +185 -183
- data/spec/watirspec/elements/date_fields_spec.rb +29 -27
- data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
- data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
- data/spec/watirspec/elements/dd_spec.rb +87 -85
- data/spec/watirspec/elements/dds_spec.rb +27 -25
- data/spec/watirspec/elements/del_spec.rb +106 -104
- data/spec/watirspec/elements/dels_spec.rb +26 -24
- data/spec/watirspec/elements/div_spec.rb +225 -221
- data/spec/watirspec/elements/divs_spec.rb +37 -35
- data/spec/watirspec/elements/dl_spec.rb +110 -108
- data/spec/watirspec/elements/dls_spec.rb +28 -26
- data/spec/watirspec/elements/dt_spec.rb +86 -84
- data/spec/watirspec/elements/dts_spec.rb +27 -25
- data/spec/watirspec/elements/element_spec.rb +794 -775
- data/spec/watirspec/elements/elements_spec.rb +40 -38
- data/spec/watirspec/elements/em_spec.rb +62 -60
- data/spec/watirspec/elements/ems_spec.rb +28 -26
- data/spec/watirspec/elements/filefield_spec.rb +116 -114
- data/spec/watirspec/elements/filefields_spec.rb +28 -26
- data/spec/watirspec/elements/font_spec.rb +20 -18
- data/spec/watirspec/elements/form_spec.rb +51 -49
- data/spec/watirspec/elements/forms_spec.rb +29 -27
- data/spec/watirspec/elements/frame_spec.rb +89 -87
- data/spec/watirspec/elements/frames_spec.rb +27 -25
- data/spec/watirspec/elements/hidden_spec.rb +81 -79
- data/spec/watirspec/elements/hiddens_spec.rb +28 -26
- data/spec/watirspec/elements/hn_spec.rb +59 -57
- data/spec/watirspec/elements/hns_spec.rb +26 -24
- data/spec/watirspec/elements/iframe_spec.rb +195 -191
- data/spec/watirspec/elements/iframes_spec.rb +31 -29
- data/spec/watirspec/elements/image_spec.rb +148 -146
- data/spec/watirspec/elements/images_spec.rb +26 -24
- data/spec/watirspec/elements/input_spec.rb +9 -7
- data/spec/watirspec/elements/ins_spec.rb +106 -104
- data/spec/watirspec/elements/inses_spec.rb +26 -24
- data/spec/watirspec/elements/label_spec.rb +56 -54
- data/spec/watirspec/elements/labels_spec.rb +26 -24
- data/spec/watirspec/elements/li_spec.rb +76 -74
- data/spec/watirspec/elements/link_spec.rb +173 -177
- data/spec/watirspec/elements/links_spec.rb +45 -43
- data/spec/watirspec/elements/lis_spec.rb +27 -25
- data/spec/watirspec/elements/list_spec.rb +44 -42
- data/spec/watirspec/elements/map_spec.rb +57 -55
- data/spec/watirspec/elements/maps_spec.rb +27 -25
- data/spec/watirspec/elements/meta_spec.rb +16 -14
- data/spec/watirspec/elements/metas_spec.rb +26 -24
- data/spec/watirspec/elements/ol_spec.rb +56 -65
- data/spec/watirspec/elements/ols_spec.rb +26 -24
- data/spec/watirspec/elements/option_spec.rb +91 -89
- data/spec/watirspec/elements/p_spec.rb +81 -79
- data/spec/watirspec/elements/pre_spec.rb +77 -75
- data/spec/watirspec/elements/pres_spec.rb +26 -24
- data/spec/watirspec/elements/ps_spec.rb +26 -24
- data/spec/watirspec/elements/radio_spec.rb +251 -249
- data/spec/watirspec/elements/radios_spec.rb +28 -26
- data/spec/watirspec/elements/select_list_spec.rb +537 -526
- data/spec/watirspec/elements/select_lists_spec.rb +32 -30
- data/spec/watirspec/elements/span_spec.rb +112 -110
- data/spec/watirspec/elements/spans_spec.rb +26 -24
- data/spec/watirspec/elements/strong_spec.rb +58 -58
- data/spec/watirspec/elements/strongs_spec.rb +28 -26
- data/spec/watirspec/elements/table_spec.rb +192 -139
- data/spec/watirspec/elements/tables_spec.rb +28 -26
- data/spec/watirspec/elements/tbody_spec.rb +74 -72
- data/spec/watirspec/elements/tbodys_spec.rb +40 -38
- data/spec/watirspec/elements/td_spec.rb +66 -64
- data/spec/watirspec/elements/tds_spec.rb +41 -39
- data/spec/watirspec/elements/text_field_spec.rb +206 -204
- data/spec/watirspec/elements/text_fields_spec.rb +30 -28
- data/spec/watirspec/elements/textarea_spec.rb +20 -18
- data/spec/watirspec/elements/textareas_spec.rb +18 -16
- data/spec/watirspec/elements/tfoot_spec.rb +65 -63
- data/spec/watirspec/elements/tfoots_spec.rb +42 -40
- data/spec/watirspec/elements/thead_spec.rb +65 -63
- data/spec/watirspec/elements/theads_spec.rb +42 -40
- data/spec/watirspec/elements/tr_spec.rb +48 -46
- data/spec/watirspec/elements/trs_spec.rb +42 -40
- data/spec/watirspec/elements/ul_spec.rb +56 -54
- data/spec/watirspec/elements/uls_spec.rb +26 -24
- data/spec/watirspec/radio_set_spec.rb +269 -267
- data/spec/watirspec/screenshot_spec.rb +20 -18
- data/spec/watirspec/scroll_spec.rb +152 -148
- data/spec/watirspec/shadow_root_spec.rb +86 -83
- data/spec/watirspec/user_editable_spec.rb +200 -198
- data/spec/watirspec/wait_spec.rb +289 -295
- data/spec/watirspec/window_switching_spec.rb +422 -434
- data/spec/watirspec_helper.rb +1 -23
- data/watir.gemspec +5 -4
- metadata +44 -33
- data/spec/watirspec/attributes_spec.rb +0 -18
- data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
- data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,428 +2,422 @@
|
|
2
2
|
|
3
3
|
require_relative '../unit_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Watir
|
6
|
+
module Locators
|
7
|
+
class Element
|
8
|
+
describe Matcher do
|
9
|
+
include LocatorSpecHelper
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
let(:query_scope) { @query_scope || browser }
|
12
|
+
let(:values_to_match) { @values_to_match || {} }
|
13
|
+
let(:matcher) { described_class.new(query_scope, values_to_match) }
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
describe '#match' do
|
16
|
+
context 'when a label element' do
|
17
|
+
it 'returns elements with for / id pairs' do
|
18
|
+
input_wds = [wd_element(tag_name: 'input', attributes: {id: 'foob_id'}),
|
19
|
+
wd_element(tag_name: 'input', attributes: {id: 'bfoo_id'}),
|
20
|
+
wd_element(tag_name: 'input', attributes: {id: 'foo_id'})]
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
label_wds = [wd_element(tag_name: 'label'),
|
23
|
+
wd_element(tag_name: 'label'),
|
24
|
+
wd_element(tag_name: 'label')]
|
22
25
|
|
23
|
-
|
26
|
+
allow(browser).to receive(:execute_script).and_return('foob', 'Foo', 'foo')
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
labels = [element(watir_element: Watir::Label, wd: label_wds[0], for: 'foob_id'),
|
29
|
+
element(watir_element: Watir::Label, wd: label_wds[1], for: 'bfoo_id'),
|
30
|
+
element(watir_element: Watir::Label, wd: label_wds[2], for: 'foo_id')]
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
expect(labels[1]).not_to receive(:for)
|
32
|
+
allow(query_scope).to receive(:labels).and_return(labels)
|
33
|
+
allow_any_instance_of(Watir::Input).to receive(:wd).and_return(input_wds[2], input_wds[2])
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
values_to_match = {label_element: 'foo'}
|
36
|
+
expect(matcher.match(input_wds, values_to_match, :all)).to eq [input_wds[2]]
|
37
|
+
# Only the Watir::Label matching the text provided will have wd called
|
38
|
+
expect(labels[0]).not_to have_received(:for)
|
39
|
+
expect(labels[1]).not_to have_received(:for)
|
40
|
+
end
|
35
41
|
|
36
|
-
|
42
|
+
it 'returns elements without for / id pairs' do
|
43
|
+
input_wds = [wd_element(tag_name: 'input'),
|
44
|
+
wd_element(tag_name: 'input'),
|
45
|
+
wd_element(tag_name: 'input')]
|
37
46
|
|
38
|
-
|
39
|
-
|
47
|
+
inputs = [element(watir_element: Watir::Input, wd: input_wds[0]),
|
48
|
+
element(watir_element: Watir::Input, wd: input_wds[1]),
|
49
|
+
element(watir_element: Watir::Input, wd: input_wds[2])]
|
40
50
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
wd_element(tag_name: 'input')]
|
51
|
+
label_wds = [wd_element(tag_name: 'label'),
|
52
|
+
wd_element(tag_name: 'label'),
|
53
|
+
wd_element(tag_name: 'label')]
|
45
54
|
|
46
|
-
|
47
|
-
element(watir_element: Watir::Input, wd: input_wds[1]),
|
48
|
-
element(watir_element: Watir::Input, wd: input_wds[2])]
|
55
|
+
allow(browser).to receive(:execute_script).and_return('foob', 'Foo', 'foo')
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
57
|
+
labels = [element(watir_element: Watir::Label, wd: label_wds[0], for: '', input: inputs[0]),
|
58
|
+
element(watir_element: Watir::Label, wd: label_wds[1], for: '', input: inputs[1]),
|
59
|
+
element(watir_element: Watir::Label, wd: label_wds[2], for: '', input: inputs[2])]
|
53
60
|
|
54
|
-
|
61
|
+
allow(query_scope).to receive(:labels).and_return(labels)
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
element(watir_element: Watir::Label, wd: label_wds[2], for: '', input: inputs[2])]
|
63
|
+
values_to_match = {label_element: 'foo'}
|
64
|
+
expect(matcher.match(input_wds, values_to_match, :all)).to eq [input_wds[2]]
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
# Only the Watir::Label matching the text provided will have wd called
|
67
|
+
expect(labels[0]).not_to have_received(:for)
|
68
|
+
expect(labels[1]).not_to have_received(:for)
|
69
|
+
end
|
63
70
|
|
64
|
-
|
71
|
+
it 'returns elements with multiple matching label text but first missing corresponding element' do
|
72
|
+
input_wds = [wd_element(tag_name: 'input'),
|
73
|
+
wd_element(tag_name: 'input')]
|
65
74
|
|
66
|
-
|
75
|
+
inputs = [element(watir_element: Watir::Input, wd: wd_element(tag_name: 'input')),
|
76
|
+
element(watir_element: Watir::Input, wd: input_wds[1])]
|
67
77
|
|
68
|
-
|
69
|
-
|
78
|
+
label_wds = [wd_element(tag_name: 'label'),
|
79
|
+
wd_element(tag_name: 'label'),
|
80
|
+
wd_element(tag_name: 'label')]
|
70
81
|
|
71
|
-
|
72
|
-
input_wds = [wd_element(tag_name: 'input'),
|
73
|
-
wd_element(tag_name: 'input')]
|
82
|
+
allow(browser).to receive(:execute_script).and_return('foo', 'foo')
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
labels = [element(watir_element: Watir::Label, wd: label_wds[0], for: '', input: inputs[0]),
|
85
|
+
element(watir_element: Watir::Label, wd: label_wds[1], for: '', input: inputs[1])]
|
77
86
|
|
78
|
-
|
79
|
-
wd_element(tag_name: 'label'),
|
80
|
-
wd_element(tag_name: 'label')]
|
87
|
+
allow(query_scope).to receive(:labels).and_return(labels)
|
81
88
|
|
82
|
-
|
89
|
+
values_to_match = {label_element: 'foo'}
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
expect(matcher.match(input_wds, values_to_match, :all)).to eq [input_wds[1]]
|
92
|
+
end
|
86
93
|
|
87
|
-
|
94
|
+
it 'returns empty Array if no label element matches' do
|
95
|
+
input_wds = [wd_element(tag_name: 'input', attributes: {id: 'foo'}),
|
96
|
+
wd_element(tag_name: 'input', attributes: {id: 'bfoo'})]
|
88
97
|
|
89
|
-
|
98
|
+
label_wds = [wd_element(tag_name: 'label'),
|
99
|
+
wd_element(tag_name: 'label'),
|
100
|
+
wd_element(tag_name: 'label')]
|
90
101
|
|
91
|
-
|
92
|
-
end
|
102
|
+
allow(browser).to receive(:execute_script).and_return('Not this', 'or this')
|
93
103
|
|
94
|
-
|
95
|
-
|
96
|
-
wd_element(tag_name: 'input', attributes: {id: 'bfoo'})]
|
104
|
+
labels = [element(watir_element: Watir::Label, wd: label_wds[0], for: 'foo'),
|
105
|
+
element(watir_element: Watir::Label, wd: label_wds[1], for: 'bfoo')]
|
97
106
|
|
98
|
-
|
99
|
-
wd_element(tag_name: 'label'),
|
100
|
-
wd_element(tag_name: 'label')]
|
107
|
+
allow(query_scope).to receive(:labels).and_return(labels)
|
101
108
|
|
102
|
-
|
109
|
+
values_to_match = {label_element: 'foo'}
|
103
110
|
|
104
|
-
|
105
|
-
|
111
|
+
expect(matcher.match(input_wds, values_to_match, :all)).to eq []
|
112
|
+
end
|
106
113
|
|
107
|
-
|
114
|
+
it 'returns empty Array if matching label elements do not have an corresponding input element' do
|
115
|
+
input_wds = [wd_element(tag_name: 'input'),
|
116
|
+
wd_element(tag_name: 'input')]
|
108
117
|
|
109
|
-
|
118
|
+
inputs = [element(watir_element: Watir::Input, wd: wd_element(tag_name: 'input')),
|
119
|
+
element(watir_element: Watir::Input, wd: wd_element(tag_name: 'input'))]
|
110
120
|
|
111
|
-
|
112
|
-
|
121
|
+
label_wds = [wd_element(tag_name: 'label'),
|
122
|
+
wd_element(tag_name: 'label')]
|
113
123
|
|
114
|
-
|
115
|
-
input_wds = [wd_element(tag_name: 'input'),
|
116
|
-
wd_element(tag_name: 'input')]
|
124
|
+
allow(browser).to receive(:execute_script).and_return('foob', 'foo')
|
117
125
|
|
118
|
-
|
119
|
-
|
126
|
+
labels = [element(watir_element: Watir::Label, wd: label_wds[0], for: '', input: inputs[0]),
|
127
|
+
element(watir_element: Watir::Label, wd: label_wds[1], for: '', input: inputs[1])]
|
120
128
|
|
121
|
-
|
122
|
-
wd_element(tag_name: 'label')]
|
129
|
+
allow(query_scope).to receive(:labels).and_return(labels)
|
123
130
|
|
124
|
-
|
131
|
+
values_to_match = {label_element: 'foo'}
|
125
132
|
|
126
|
-
|
127
|
-
|
133
|
+
expect(matcher.match(input_wds, values_to_match, :all)).to eq []
|
134
|
+
end
|
135
|
+
end
|
128
136
|
|
129
|
-
|
137
|
+
context 'when locating one element' do
|
138
|
+
before { @filter = :first }
|
130
139
|
|
131
|
-
|
140
|
+
it 'by tag name' do
|
141
|
+
elements = [wd_element(tag_name: 'div'),
|
142
|
+
wd_element(tag_name: 'span')]
|
143
|
+
@values_to_match = {tag_name: 'span'}
|
132
144
|
|
133
|
-
|
134
|
-
|
135
|
-
end
|
145
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
146
|
+
end
|
136
147
|
|
137
|
-
|
138
|
-
|
148
|
+
it 'by attribute' do
|
149
|
+
elements = [wd_element(attributes: {id: 'foo'}),
|
150
|
+
wd_element(attributes: {id: 'bar'}),
|
151
|
+
wd_element(attributes: {id: 'foobar'})]
|
152
|
+
@values_to_match = {id: 'foobar'}
|
139
153
|
|
140
|
-
|
141
|
-
|
142
|
-
wd_element(tag_name: 'span')]
|
143
|
-
@values_to_match = {tag_name: 'span'}
|
154
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[2]
|
155
|
+
end
|
144
156
|
|
145
|
-
|
146
|
-
|
157
|
+
it 'by class array' do
|
158
|
+
elements = [wd_element(attributes: {class: 'foob bar'}),
|
159
|
+
wd_element(attributes: {class: 'bar'}),
|
160
|
+
wd_element(attributes: {class: 'bar foo'})]
|
161
|
+
@values_to_match = {class: %w[foo bar]}
|
147
162
|
|
148
|
-
|
149
|
-
|
150
|
-
wd_element(attributes: {id: 'bar'}),
|
151
|
-
wd_element(attributes: {id: 'foobar'})]
|
152
|
-
@values_to_match = {id: 'foobar'}
|
163
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[2]
|
164
|
+
end
|
153
165
|
|
154
|
-
|
155
|
-
|
166
|
+
it 'by positive index' do
|
167
|
+
elements = [wd_element(tag_name: 'div'),
|
168
|
+
wd_element(tag_name: 'span'),
|
169
|
+
wd_element(tag_name: 'div')]
|
156
170
|
|
157
|
-
|
158
|
-
elements = [wd_element(attributes: {class: 'foob bar'}),
|
159
|
-
wd_element(attributes: {class: 'bar'}),
|
160
|
-
wd_element(attributes: {class: 'bar foo'})]
|
161
|
-
@values_to_match = {class: %w[foo bar]}
|
171
|
+
@values_to_match = {tag_name: 'div', index: 1}
|
162
172
|
|
163
|
-
|
164
|
-
|
173
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[2]
|
174
|
+
end
|
165
175
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
176
|
+
it 'by negative index' do
|
177
|
+
elements = [wd_element(tag_name: 'div'),
|
178
|
+
wd_element(tag_name: 'span'),
|
179
|
+
wd_element(tag_name: 'div')]
|
170
180
|
|
171
|
-
|
181
|
+
@values_to_match = {tag_name: 'div', index: -1}
|
172
182
|
|
173
|
-
|
174
|
-
|
183
|
+
expect(matcher.match(elements.dup, values_to_match, @filter)).to eq elements[2]
|
184
|
+
end
|
175
185
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
186
|
+
it 'by visibility true' do
|
187
|
+
elements = [wd_element(tag_name: 'div', displayed?: false),
|
188
|
+
wd_element(tag_name: 'span', displayed?: true)]
|
189
|
+
@values_to_match = {visible: true}
|
180
190
|
|
181
|
-
|
191
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
192
|
+
end
|
182
193
|
|
183
|
-
|
184
|
-
|
194
|
+
it 'by visibility false' do
|
195
|
+
elements = [wd_element(tag_name: 'div', displayed?: true),
|
196
|
+
wd_element(tag_name: 'span', displayed?: false)]
|
197
|
+
@values_to_match = {visible: false}
|
185
198
|
|
186
|
-
|
187
|
-
|
188
|
-
wd_element(tag_name: 'span', displayed?: true)]
|
189
|
-
@values_to_match = {visible: true}
|
199
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
200
|
+
end
|
190
201
|
|
191
|
-
|
192
|
-
|
202
|
+
it 'by text' do
|
203
|
+
elements = [wd_element, wd_element]
|
204
|
+
@values_to_match = {text: 'Foob'}
|
193
205
|
|
194
|
-
|
195
|
-
elements = [wd_element(tag_name: 'div', displayed?: true),
|
196
|
-
wd_element(tag_name: 'span', displayed?: false)]
|
197
|
-
@values_to_match = {visible: false}
|
206
|
+
allow(browser).to receive(:execute_script).and_return('foo', 'Foob')
|
198
207
|
|
199
|
-
|
200
|
-
|
208
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
209
|
+
end
|
201
210
|
|
202
|
-
|
203
|
-
|
204
|
-
|
211
|
+
it 'by visible text' do
|
212
|
+
elements = [wd_element(text: 'foo'),
|
213
|
+
wd_element(text: 'Foob')]
|
214
|
+
@values_to_match = {visible_text: /Foo|Bar/}
|
205
215
|
|
206
|
-
|
216
|
+
allow(elements[0]).to receive(:text).and_return 'foo'
|
217
|
+
allow(elements[1]).to receive(:text).and_return 'Foob'
|
207
218
|
|
208
|
-
|
209
|
-
|
219
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
220
|
+
end
|
210
221
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
222
|
+
it 'by href' do
|
223
|
+
elements = [wd_element(tag_name: 'div', attributes: {href: 'froo.com'}),
|
224
|
+
wd_element(tag_name: 'span', attributes: {href: 'bar.com'})]
|
225
|
+
@values_to_match = {href: /foo|bar/}
|
215
226
|
|
216
|
-
|
217
|
-
|
227
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq elements[1]
|
228
|
+
end
|
218
229
|
|
219
|
-
|
220
|
-
|
230
|
+
it "returns nil if found element doesn't match the selector tag_name" do
|
231
|
+
elements = [wd_element(tag_name: 'div')]
|
221
232
|
|
222
|
-
|
223
|
-
elements = [wd_element(tag_name: 'div', attributes: {href: 'froo.com'}),
|
224
|
-
wd_element(tag_name: 'span', attributes: {href: 'bar.com'})]
|
225
|
-
@values_to_match = {href: /foo|bar/}
|
233
|
+
@values_to_match = {tag_name: 'span'}
|
226
234
|
|
227
|
-
|
228
|
-
|
235
|
+
expect(matcher.match(elements, values_to_match, @filter)).to be_nil
|
236
|
+
end
|
237
|
+
end
|
229
238
|
|
230
|
-
|
231
|
-
|
239
|
+
context 'when locating collection' do
|
240
|
+
before { @filter = :all }
|
232
241
|
|
233
|
-
|
242
|
+
it 'by tag name' do
|
243
|
+
elements = [wd_element(tag_name: 'div'),
|
244
|
+
wd_element(tag_name: 'span'),
|
245
|
+
wd_element(tag_name: 'div')]
|
246
|
+
@values_to_match = {tag_name: 'div'}
|
234
247
|
|
235
|
-
|
236
|
-
|
237
|
-
end
|
248
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
249
|
+
end
|
238
250
|
|
239
|
-
|
240
|
-
|
251
|
+
it 'by attribute' do
|
252
|
+
elements = [wd_element(attributes: {foo: 'foo'}),
|
253
|
+
wd_element(attributes: {foo: 'bar'}),
|
254
|
+
wd_element(attributes: {foo: 'foo'})]
|
255
|
+
@values_to_match = {foo: 'foo'}
|
241
256
|
|
242
|
-
|
243
|
-
|
244
|
-
wd_element(tag_name: 'span'),
|
245
|
-
wd_element(tag_name: 'div')]
|
246
|
-
@values_to_match = {tag_name: 'div'}
|
257
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
258
|
+
end
|
247
259
|
|
248
|
-
|
249
|
-
|
260
|
+
it 'by single class' do
|
261
|
+
elements = [wd_element(attributes: {class: 'foo bar cool'}),
|
262
|
+
wd_element(attributes: {class: 'foob bar'}),
|
263
|
+
wd_element(attributes: {class: 'bar foo foobar'})]
|
264
|
+
@values_to_match = {class: 'foo'}
|
250
265
|
|
251
|
-
|
252
|
-
|
253
|
-
wd_element(attributes: {foo: 'bar'}),
|
254
|
-
wd_element(attributes: {foo: 'foo'})]
|
255
|
-
@values_to_match = {foo: 'foo'}
|
266
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
267
|
+
end
|
256
268
|
|
257
|
-
|
258
|
-
|
269
|
+
it 'by class array' do
|
270
|
+
elements = [wd_element(attributes: {class: 'foo bar cool'}),
|
271
|
+
wd_element(attributes: {class: 'foob bar'}),
|
272
|
+
wd_element(attributes: {class: 'bar foo foobar'})]
|
273
|
+
@values_to_match = {class: %w[foo bar]}
|
259
274
|
|
260
|
-
|
261
|
-
|
262
|
-
wd_element(attributes: {class: 'foob bar'}),
|
263
|
-
wd_element(attributes: {class: 'bar foo foobar'})]
|
264
|
-
@values_to_match = {class: 'foo'}
|
275
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
276
|
+
end
|
265
277
|
|
266
|
-
|
267
|
-
|
278
|
+
it 'by visibility true' do
|
279
|
+
elements = [wd_element(tag_name: 'div'),
|
280
|
+
wd_element(tag_name: 'span'),
|
281
|
+
wd_element(tag_name: 'div')]
|
282
|
+
@values_to_match = {visible: true}
|
268
283
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
wd_element(attributes: {class: 'bar foo foobar'})]
|
273
|
-
@values_to_match = {class: %w[foo bar]}
|
284
|
+
allow(elements[0]).to receive(:displayed?).and_return false
|
285
|
+
allow(elements[1]).to receive(:displayed?).and_return true
|
286
|
+
allow(elements[2]).to receive(:displayed?).and_return true
|
274
287
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
it 'by visibility true' do
|
279
|
-
elements = [wd_element(tag_name: 'div'),
|
280
|
-
wd_element(tag_name: 'span'),
|
281
|
-
wd_element(tag_name: 'div')]
|
282
|
-
@values_to_match = {visible: true}
|
288
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
289
|
+
end
|
283
290
|
|
284
|
-
|
285
|
-
|
286
|
-
|
291
|
+
it 'by visibility false' do
|
292
|
+
elements = [wd_element(displayed?: false),
|
293
|
+
wd_element(displayed?: true),
|
294
|
+
wd_element(displayed?: false)]
|
295
|
+
@values_to_match = {visible: false}
|
287
296
|
|
288
|
-
|
289
|
-
|
297
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
298
|
+
end
|
290
299
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
wd_element(displayed?: false)]
|
295
|
-
@values_to_match = {visible: false}
|
296
|
-
|
297
|
-
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
298
|
-
end
|
300
|
+
it 'by text' do
|
301
|
+
elements = [wd_element, wd_element, wd_element]
|
302
|
+
@values_to_match = {text: /Foo|Bar/}
|
299
303
|
|
300
|
-
|
301
|
-
elements = [wd_element, wd_element, wd_element]
|
302
|
-
@values_to_match = {text: /Foo|Bar/}
|
304
|
+
allow(browser).to receive(:execute_script).and_return('foo', 'Foob', 'bBarb')
|
303
305
|
|
304
|
-
|
306
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
307
|
+
end
|
305
308
|
|
306
|
-
|
307
|
-
|
309
|
+
it 'by visible text' do
|
310
|
+
elements = [wd_element(text: 'foo'),
|
311
|
+
wd_element(text: 'Foob'),
|
312
|
+
wd_element(text: 'bBarb')]
|
313
|
+
@values_to_match = {visible_text: /Foo|Bar/}
|
308
314
|
|
309
|
-
|
310
|
-
|
311
|
-
wd_element(text: 'Foob'),
|
312
|
-
wd_element(text: 'bBarb')]
|
313
|
-
@values_to_match = {visible_text: /Foo|Bar/}
|
315
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
316
|
+
end
|
314
317
|
|
315
|
-
|
316
|
-
|
318
|
+
it 'by href' do
|
319
|
+
elements = [wd_element(attributes: {href: 'froo.com'}),
|
320
|
+
wd_element(attributes: {href: 'bar.com'}),
|
321
|
+
wd_element(attributes: {href: 'foobar.com'})]
|
322
|
+
@values_to_match = {href: /foo|bar/}
|
317
323
|
|
318
|
-
|
319
|
-
|
320
|
-
wd_element(attributes: {href: 'bar.com'}),
|
321
|
-
wd_element(attributes: {href: 'foobar.com'})]
|
322
|
-
@values_to_match = {href: /foo|bar/}
|
324
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
325
|
+
end
|
323
326
|
|
324
|
-
|
325
|
-
|
327
|
+
it 'returns empty Array if found no element matches the selector tag_name' do
|
328
|
+
elements = [wd_element(tag_name: 'div')]
|
326
329
|
|
327
|
-
|
328
|
-
elements = [wd_element(tag_name: 'div')]
|
330
|
+
@values_to_match = {tag_name: 'span'}
|
329
331
|
|
330
|
-
|
332
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq []
|
333
|
+
end
|
334
|
+
end
|
331
335
|
|
332
|
-
|
333
|
-
|
334
|
-
|
336
|
+
context 'when matching Regular Expressions' do
|
337
|
+
it 'with white space' do
|
338
|
+
allow(browser).to receive(:execute_script).and_return("\n match this \n", 'no', 'match this')
|
335
339
|
|
336
|
-
|
337
|
-
|
338
|
-
|
340
|
+
elements = [wd_element,
|
341
|
+
wd_element,
|
342
|
+
wd_element]
|
343
|
+
@values_to_match = {text: /^match this$/}
|
339
344
|
|
340
|
-
|
341
|
-
|
342
|
-
wd_element]
|
343
|
-
@values_to_match = {text: /^match this$/}
|
345
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
346
|
+
end
|
344
347
|
|
345
|
-
|
346
|
-
|
348
|
+
it 'with tag_name' do
|
349
|
+
elements = [wd_element(tag_name: 'div'),
|
350
|
+
wd_element(tag_name: 'span'),
|
351
|
+
wd_element(tag_name: 'div')]
|
352
|
+
@values_to_match = {tag_name: /d|q/}
|
347
353
|
|
348
|
-
|
349
|
-
|
350
|
-
wd_element(tag_name: 'span'),
|
351
|
-
wd_element(tag_name: 'div')]
|
352
|
-
@values_to_match = {tag_name: /d|q/}
|
354
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
355
|
+
end
|
353
356
|
|
354
|
-
|
355
|
-
|
357
|
+
it 'with single class' do
|
358
|
+
elements = [wd_element(attributes: {class: 'foo bar cool'}),
|
359
|
+
wd_element(attributes: {class: 'foob bar'}),
|
360
|
+
wd_element(attributes: {class: 'bar foo foobar'})]
|
361
|
+
@values_to_match = {class: /foob|q/}
|
356
362
|
|
357
|
-
|
358
|
-
|
359
|
-
wd_element(attributes: {class: 'foob bar'}),
|
360
|
-
wd_element(attributes: {class: 'bar foo foobar'})]
|
361
|
-
@values_to_match = {class: /foob|q/}
|
363
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
364
|
+
end
|
362
365
|
|
363
|
-
|
364
|
-
|
366
|
+
it 'with multiple classes' do
|
367
|
+
elements = [wd_element(attributes: {class: 'foo bar cool'}),
|
368
|
+
wd_element(attributes: {class: 'foob bar'}),
|
369
|
+
wd_element(attributes: {class: 'bar foo foobar'})]
|
370
|
+
@values_to_match = {class: [/foob/, /bar/]}
|
365
371
|
|
366
|
-
|
367
|
-
|
368
|
-
wd_element(attributes: {class: 'foob bar'}),
|
369
|
-
wd_element(attributes: {class: 'bar foo foobar'})]
|
370
|
-
@values_to_match = {class: [/foob/, /bar/]}
|
372
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[1], elements[2]]
|
373
|
+
end
|
371
374
|
|
372
|
-
|
373
|
-
|
375
|
+
it 'with attributes' do
|
376
|
+
elements = [wd_element(attributes: {foo: 'foo'}),
|
377
|
+
wd_element(attributes: {foo: 'bar'}),
|
378
|
+
wd_element(attributes: {foo: 'foo'})]
|
379
|
+
@values_to_match = {foo: /fo/}
|
374
380
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
wd_element(attributes: {foo: 'foo'})]
|
379
|
-
@values_to_match = {foo: /fo/}
|
381
|
+
expect(matcher.match(elements, values_to_match, @filter)).to eq [elements[0], elements[2]]
|
382
|
+
end
|
383
|
+
end
|
380
384
|
|
381
|
-
|
382
|
-
|
383
|
-
end
|
385
|
+
context 'when matching text Regexp' do
|
386
|
+
let(:elements) { [wd_element, wd_element] }
|
384
387
|
|
385
|
-
|
386
|
-
# See equivalent tests in checkbox_spec
|
387
|
-
context 'text_regexp deprecations' do
|
388
|
-
let(:filter) { :first }
|
389
|
-
let(:elements) { [wd_element, wd_element] }
|
388
|
+
before { allow(browser).to receive(:execute_script).and_return('all visible', 'some visible') }
|
390
389
|
|
391
|
-
|
392
|
-
|
393
|
-
allow(browser).to receive(:execute_script).and_return('all visible', 'some visible')
|
390
|
+
it 'not thrown when still matched by text content' do
|
391
|
+
values_to_match = {text: /some visible/}
|
394
392
|
|
395
|
-
|
396
|
-
|
393
|
+
expect(matcher.match(elements, values_to_match, :first)).to eq elements[1]
|
394
|
+
end
|
397
395
|
|
398
|
-
|
399
|
-
|
400
|
-
allow(browser).to receive(:execute_script).and_return('all visible', 'some visible')
|
396
|
+
it 'not thrown with complex regexp matched by text content' do
|
397
|
+
values_to_match = {text: /some (in|)visible/}
|
401
398
|
|
402
|
-
|
403
|
-
|
399
|
+
expect(matcher.match(elements, values_to_match, :first)).to eq elements[1]
|
400
|
+
end
|
404
401
|
|
405
|
-
|
406
|
-
|
407
|
-
allow(browser).to receive(:execute_script).and_return('all visible', 'some visible')
|
408
|
-
allow(browser).to receive(:timer).and_return(Watir::Wait::Timer.new)
|
409
|
-
allow(browser).to receive(:timer=).and_return(Watir::Wait::Timer.new)
|
402
|
+
it 'thrown when no longer matched by text content' do
|
403
|
+
values_to_match = {text: /some visible$/}
|
410
404
|
|
411
|
-
|
412
|
-
|
405
|
+
expect(matcher.match(elements, values_to_match, :first)).to eq elements[1]
|
406
|
+
end
|
413
407
|
|
414
|
-
|
415
|
-
|
416
|
-
allow(browser).to receive(:execute_script).and_return('all visible', 'some visible')
|
408
|
+
it 'not thrown when element does not exist' do
|
409
|
+
values_to_match = {text: /definitely not there/}
|
417
410
|
|
418
|
-
|
419
|
-
|
411
|
+
expect(matcher.match(elements, values_to_match, :first)).to be_nil
|
412
|
+
end
|
420
413
|
|
421
|
-
|
422
|
-
|
423
|
-
@values_to_match = {text: /some visible some hidden/}
|
424
|
-
allow(browser).to receive(:execute_script).and_return('all visible', 'some visible')
|
414
|
+
it 'keeps element from being located' do
|
415
|
+
values_to_match = {text: /some visible some hidden/}
|
425
416
|
|
426
|
-
|
417
|
+
expect(matcher.match(elements, values_to_match, :first)).to be_nil
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
427
421
|
end
|
428
422
|
end
|
429
423
|
end
|