watir 6.13.0 → 6.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +141 -0
- data/.travis.yml +6 -0
- data/CHANGES.md +12 -0
- data/Gemfile +4 -10
- data/README.md +64 -49
- data/Rakefile +28 -16
- data/lib/watir.rb +13 -15
- data/lib/watir/adjacent.rb +15 -13
- data/lib/watir/after_hooks.rb +8 -10
- data/lib/watir/alert.rb +7 -8
- data/lib/watir/aliases.rb +2 -2
- data/lib/watir/attribute_helper.rb +18 -20
- data/lib/watir/browser.rb +42 -75
- data/lib/watir/capabilities.rb +19 -10
- data/lib/watir/cell_container.rb +0 -2
- data/lib/watir/container.rb +4 -4
- data/lib/watir/cookies.rb +7 -8
- data/lib/watir/element_collection.rb +37 -22
- data/lib/watir/elements/area.rb +0 -2
- data/lib/watir/elements/button.rb +1 -3
- data/lib/watir/elements/cell.rb +0 -1
- data/lib/watir/elements/checkbox.rb +5 -7
- data/lib/watir/elements/date_field.rb +5 -9
- data/lib/watir/elements/date_time_field.rb +6 -10
- data/lib/watir/elements/dlist.rb +2 -4
- data/lib/watir/elements/element.rb +201 -99
- data/lib/watir/elements/file_field.rb +3 -4
- data/lib/watir/elements/font.rb +2 -4
- data/lib/watir/elements/form.rb +0 -2
- data/lib/watir/elements/hidden.rb +3 -4
- data/lib/watir/elements/html_elements.rb +24 -76
- data/lib/watir/elements/iframe.rb +57 -71
- data/lib/watir/elements/image.rb +3 -4
- data/lib/watir/elements/input.rb +0 -2
- data/lib/watir/elements/link.rb +2 -5
- data/lib/watir/elements/list.rb +4 -4
- data/lib/watir/elements/option.rb +3 -6
- data/lib/watir/elements/radio.rb +4 -6
- data/lib/watir/elements/row.rb +0 -1
- data/lib/watir/elements/select.rb +41 -43
- data/lib/watir/elements/svg_elements.rb +0 -116
- data/lib/watir/elements/table.rb +1 -2
- data/lib/watir/elements/table_cell.rb +2 -3
- data/lib/watir/elements/text_field.rb +4 -6
- data/lib/watir/exception.rb +0 -1
- data/lib/watir/extensions/nokogiri.rb +2 -4
- data/lib/watir/generator.rb +3 -3
- data/lib/watir/generator/base.rb +10 -10
- data/lib/watir/generator/base/generator.rb +26 -29
- data/lib/watir/generator/base/idl_sorter.rb +34 -32
- data/lib/watir/generator/base/spec_extractor.rb +132 -114
- data/lib/watir/generator/base/util.rb +1 -3
- data/lib/watir/generator/base/visitor.rb +140 -140
- data/lib/watir/generator/html.rb +4 -4
- data/lib/watir/generator/html/generator.rb +2 -4
- data/lib/watir/generator/html/spec_extractor.rb +33 -33
- data/lib/watir/generator/html/visitor.rb +14 -14
- data/lib/watir/generator/svg.rb +3 -3
- data/lib/watir/generator/svg/generator.rb +1 -3
- data/lib/watir/generator/svg/spec_extractor.rb +35 -35
- data/lib/watir/generator/svg/visitor.rb +14 -14
- data/lib/watir/has_window.rb +2 -4
- data/lib/watir/js_execution.rb +7 -9
- data/lib/watir/js_snippets.rb +3 -3
- data/lib/watir/js_snippets/attributeValues.js +11 -0
- data/lib/watir/legacy_wait.rb +7 -12
- data/lib/watir/locators.rb +9 -11
- data/lib/watir/locators/button/locator.rb +2 -3
- data/lib/watir/locators/button/selector_builder.rb +9 -9
- data/lib/watir/locators/button/selector_builder/xpath.rb +1 -1
- data/lib/watir/locators/button/validator.rb +2 -2
- data/lib/watir/locators/cell/locator.rb +0 -2
- data/lib/watir/locators/cell/selector_builder.rb +3 -5
- data/lib/watir/locators/element/locator.rb +85 -64
- data/lib/watir/locators/element/selector_builder.rb +40 -38
- data/lib/watir/locators/element/selector_builder/xpath.rb +20 -18
- data/lib/watir/locators/element/validator.rb +1 -1
- data/lib/watir/locators/row/locator.rb +0 -2
- data/lib/watir/locators/row/selector_builder.rb +6 -9
- data/lib/watir/locators/text_area/selector_builder.rb +1 -1
- data/lib/watir/locators/text_field/locator.rb +1 -3
- data/lib/watir/locators/text_field/selector_builder.rb +5 -5
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +1 -1
- data/lib/watir/locators/text_field/validator.rb +3 -2
- data/lib/watir/logger.rb +11 -21
- data/lib/watir/navigation.rb +49 -0
- data/lib/watir/radio_set.rb +17 -18
- data/lib/watir/row_container.rb +3 -5
- data/lib/watir/screenshot.rb +2 -4
- data/lib/watir/user_editable.rb +13 -8
- data/lib/watir/version.rb +3 -0
- data/lib/watir/wait.rb +56 -55
- data/lib/watir/wait/timer.rb +1 -3
- data/lib/watir/window.rb +36 -45
- data/lib/watir/xpath_support.rb +1 -3
- data/lib/watirspec.rb +11 -11
- data/lib/watirspec/guards.rb +10 -7
- data/lib/watirspec/implementation.rb +3 -4
- data/lib/watirspec/rake_tasks.rb +30 -29
- data/lib/watirspec/remote_server.rb +3 -3
- data/lib/watirspec/runner.rb +1 -2
- data/lib/watirspec/server.rb +3 -0
- data/lib/watirspec/server/app.rb +14 -6
- data/spec/implementation_spec.rb +9 -9
- data/spec/locator_spec_helper.rb +3 -4
- data/spec/spec_helper.rb +3 -7
- data/spec/unit/container_spec.rb +9 -10
- data/spec/unit/element_locator_spec.rb +224 -219
- data/spec/unit/logger_spec.rb +4 -4
- data/spec/unit/unit_helper.rb +0 -2
- data/spec/unit/wait_spec.rb +26 -28
- data/spec/watirspec/adjacent_spec.rb +130 -130
- data/spec/watirspec/after_hooks_spec.rb +63 -63
- data/spec/watirspec/alert_spec.rb +6 -6
- data/spec/watirspec/attributes_spec.rb +6 -6
- data/spec/watirspec/browser_spec.rb +161 -162
- data/spec/watirspec/click_spec.rb +9 -9
- data/spec/watirspec/cookies_spec.rb +15 -14
- data/spec/watirspec/drag_and_drop_spec.rb +15 -16
- data/spec/watirspec/element_hidden_spec.rb +19 -21
- data/spec/watirspec/elements/area_spec.rb +18 -21
- data/spec/watirspec/elements/areas_spec.rb +13 -15
- data/spec/watirspec/elements/button_spec.rb +96 -99
- data/spec/watirspec/elements/buttons_spec.rb +17 -19
- data/spec/watirspec/elements/checkbox_spec.rb +102 -100
- data/spec/watirspec/elements/checkboxes_spec.rb +13 -15
- data/spec/watirspec/elements/collections_spec.rb +35 -37
- data/spec/watirspec/elements/date_field_spec.rb +46 -47
- data/spec/watirspec/elements/date_fields_spec.rb +13 -15
- data/spec/watirspec/elements/date_time_field_spec.rb +62 -57
- data/spec/watirspec/elements/date_time_fields_spec.rb +14 -15
- data/spec/watirspec/elements/dd_spec.rb +46 -48
- data/spec/watirspec/elements/dds_spec.rb +13 -15
- data/spec/watirspec/elements/del_spec.rb +27 -28
- data/spec/watirspec/elements/dels_spec.rb +13 -15
- data/spec/watirspec/elements/div_spec.rb +89 -91
- data/spec/watirspec/elements/divs_spec.rb +17 -19
- data/spec/watirspec/elements/dl_spec.rb +52 -54
- data/spec/watirspec/elements/dls_spec.rb +13 -15
- data/spec/watirspec/elements/dt_spec.rb +46 -48
- data/spec/watirspec/elements/dts_spec.rb +13 -15
- data/spec/watirspec/elements/element_spec.rb +240 -189
- data/spec/watirspec/elements/elements_spec.rb +16 -16
- data/spec/watirspec/elements/em_spec.rb +38 -40
- data/spec/watirspec/elements/ems_spec.rb +13 -15
- data/spec/watirspec/elements/filefield_spec.rb +45 -46
- data/spec/watirspec/elements/filefields_spec.rb +13 -15
- data/spec/watirspec/elements/font_spec.rb +11 -13
- data/spec/watirspec/elements/form_spec.rb +13 -15
- data/spec/watirspec/elements/forms_spec.rb +13 -15
- data/spec/watirspec/elements/frame_spec.rb +48 -50
- data/spec/watirspec/elements/frames_spec.rb +13 -15
- data/spec/watirspec/elements/hidden_spec.rb +23 -25
- data/spec/watirspec/elements/hiddens_spec.rb +13 -15
- data/spec/watirspec/elements/hn_spec.rb +22 -24
- data/spec/watirspec/elements/hns_spec.rb +13 -13
- data/spec/watirspec/elements/iframe_spec.rb +106 -74
- data/spec/watirspec/elements/iframes_spec.rb +16 -18
- data/spec/watirspec/elements/image_spec.rb +30 -32
- data/spec/watirspec/elements/images_spec.rb +13 -15
- data/spec/watirspec/elements/input_spec.rb +4 -5
- data/spec/watirspec/elements/ins_spec.rb +27 -29
- data/spec/watirspec/elements/inses_spec.rb +13 -15
- data/spec/watirspec/elements/label_spec.rb +17 -19
- data/spec/watirspec/elements/labels_spec.rb +13 -15
- data/spec/watirspec/elements/li_spec.rb +23 -25
- data/spec/watirspec/elements/link_spec.rb +45 -48
- data/spec/watirspec/elements/links_spec.rb +14 -16
- data/spec/watirspec/elements/lis_spec.rb +13 -15
- data/spec/watirspec/elements/list_spec.rb +14 -15
- data/spec/watirspec/elements/map_spec.rb +19 -20
- data/spec/watirspec/elements/maps_spec.rb +13 -15
- data/spec/watirspec/elements/meta_spec.rb +10 -10
- data/spec/watirspec/elements/metas_spec.rb +13 -15
- data/spec/watirspec/elements/ol_spec.rb +20 -21
- data/spec/watirspec/elements/ols_spec.rb +13 -15
- data/spec/watirspec/elements/option_spec.rb +63 -63
- data/spec/watirspec/elements/p_spec.rb +27 -26
- data/spec/watirspec/elements/pre_spec.rb +24 -25
- data/spec/watirspec/elements/pres_spec.rb +13 -15
- data/spec/watirspec/elements/ps_spec.rb +13 -15
- data/spec/watirspec/elements/radio_spec.rb +96 -97
- data/spec/watirspec/elements/radios_spec.rb +13 -15
- data/spec/watirspec/elements/select_list_spec.rb +244 -237
- data/spec/watirspec/elements/select_lists_spec.rb +15 -16
- data/spec/watirspec/elements/span_spec.rb +32 -31
- data/spec/watirspec/elements/spans_spec.rb +13 -15
- data/spec/watirspec/elements/strong_spec.rb +23 -24
- data/spec/watirspec/elements/strongs_spec.rb +13 -15
- data/spec/watirspec/elements/table_nesting_spec.rb +15 -14
- data/spec/watirspec/elements/table_spec.rb +61 -62
- data/spec/watirspec/elements/tables_spec.rb +15 -17
- data/spec/watirspec/elements/tbody_spec.rb +25 -26
- data/spec/watirspec/elements/tbodys_spec.rb +17 -19
- data/spec/watirspec/elements/td_spec.rb +20 -22
- data/spec/watirspec/elements/tds_spec.rb +9 -11
- data/spec/watirspec/elements/text_field_spec.rb +55 -56
- data/spec/watirspec/elements/text_fields_spec.rb +15 -16
- data/spec/watirspec/elements/textarea_spec.rb +2 -2
- data/spec/watirspec/elements/textareas_spec.rb +1 -1
- data/spec/watirspec/elements/tfoot_spec.rb +22 -23
- data/spec/watirspec/elements/tfoots_spec.rb +19 -19
- data/spec/watirspec/elements/thead_spec.rb +21 -23
- data/spec/watirspec/elements/theads_spec.rb +19 -19
- data/spec/watirspec/elements/tr_spec.rb +20 -22
- data/spec/watirspec/elements/trs_spec.rb +17 -19
- data/spec/watirspec/elements/ul_spec.rb +17 -19
- data/spec/watirspec/elements/uls_spec.rb +13 -14
- data/spec/watirspec/html/data_attributes.html +1 -0
- data/spec/watirspec/radio_set_spec.rb +100 -99
- data/spec/watirspec/relaxed_locate_spec.rb +19 -43
- data/spec/watirspec/screenshot_spec.rb +4 -4
- data/spec/watirspec/special_chars_spec.rb +2 -4
- data/spec/watirspec/support/rspec_matchers.rb +85 -22
- data/spec/watirspec/user_editable_spec.rb +84 -85
- data/spec/watirspec/wait_spec.rb +74 -95
- data/spec/watirspec/window_switching_spec.rb +131 -132
- data/spec/watirspec_helper.rb +12 -9
- data/support/travis.sh +4 -0
- data/support/version_differ.rb +12 -13
- data/watir.gemspec +29 -22
- metadata +76 -50
@@ -3,177 +3,178 @@ require_relative 'unit_helper'
|
|
3
3
|
describe Watir::Locators::Element::Locator do
|
4
4
|
include LocatorSpecHelper
|
5
5
|
|
6
|
-
describe
|
7
|
-
describe
|
6
|
+
describe 'finds a single element' do
|
7
|
+
describe 'by delegating to Selenium' do
|
8
8
|
SELENIUM_SELECTORS.each do |loc|
|
9
9
|
it "delegates to Selenium's #{loc} locator" do
|
10
|
-
expect_one(loc,
|
10
|
+
expect_one(loc, 'bar').and_return(element(tag_name: 'div'))
|
11
11
|
match = %i[link link_text partial_link_text].include?(loc) ? :to : :to_not
|
12
12
|
msg = /:#{loc} locator is deprecated\. Use :visible_text instead/
|
13
|
-
expect { locate_one loc =>
|
13
|
+
expect { locate_one loc => 'bar' }.send(match, output(msg).to_stdout_from_any_process)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
expect_one :xpath, "
|
18
|
+
describe 'with selectors not supported by Selenium' do
|
19
|
+
it 'handles selector with tag name and a single attribute' do
|
20
|
+
expect_one :xpath, ".//*[local-name()='div'][@title='foo']"
|
21
21
|
|
22
|
-
locate_one tag_name:
|
23
|
-
title:
|
22
|
+
locate_one tag_name: 'div',
|
23
|
+
title: 'foo'
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'handles selector with no tag name and and a single attribute' do
|
27
27
|
expect_one :xpath, ".//*[@title='foo']"
|
28
28
|
|
29
|
-
locate_one title:
|
29
|
+
locate_one title: 'foo'
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'handles single quotes in the attribute string' do
|
33
33
|
expect_one :xpath, %{.//*[@title=concat('foo and ',"'",'bar',"'",'')]}
|
34
34
|
|
35
35
|
locate_one title: "foo and 'bar'"
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
expect_one :xpath, "
|
38
|
+
it 'handles selector with tag name and multiple attributes' do
|
39
|
+
expect_one :xpath, ".//*[local-name()='div'][@title='foo' and @dir='bar']"
|
40
40
|
|
41
|
-
locate_one [:tag_name,
|
42
|
-
:title
|
43
|
-
:dir
|
41
|
+
locate_one [:tag_name, 'div',
|
42
|
+
:title, 'foo',
|
43
|
+
:dir, 'bar']
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'handles selector with no tag name and multiple attributes' do
|
47
47
|
expect_one :xpath, ".//*[@dir='foo' and @title='bar']"
|
48
48
|
|
49
|
-
locate_one [:dir,
|
50
|
-
:title,
|
49
|
+
locate_one [:dir, 'foo',
|
50
|
+
:title, 'bar']
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
expect_one :xpath,
|
53
|
+
it 'handles selector with attribute presence' do
|
54
|
+
expect_one :xpath, './/*[@data-view]'
|
55
55
|
|
56
56
|
locate_one [:data_view, true]
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
expect_one :xpath,
|
59
|
+
it 'handles selector with attribute absence' do
|
60
|
+
expect_one :xpath, './/*[not(@data-view)]'
|
61
61
|
|
62
62
|
locate_one [:data_view, false]
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
expect_one :xpath,
|
65
|
+
it 'handles selector with class attribute presence' do
|
66
|
+
expect_one :xpath, './/*[@class]'
|
67
67
|
|
68
68
|
locate_one class: true
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
|
71
|
+
it 'handles selector with multiple classes in array' do
|
72
|
+
xpath = ".//*[(contains(concat(' ', @class, ' '), ' a ') and contains(concat(' ', @class, ' '), ' b '))]"
|
73
|
+
expect_one :xpath, xpath
|
73
74
|
|
74
|
-
locate_one class: [
|
75
|
+
locate_one class: %w[a b]
|
75
76
|
end
|
76
77
|
|
77
|
-
it
|
78
|
+
it 'handles selector with multiple classes in string' do
|
78
79
|
expect_one :xpath, ".//*[contains(concat(' ', @class, ' '), ' a b ')]"
|
79
80
|
|
80
|
-
expect { locate_one class:
|
81
|
+
expect { locate_one class: 'a b' }.to have_deprecated_class_array
|
81
82
|
end
|
82
83
|
|
83
|
-
it
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
it 'handles selector with tag_name and xpath' do
|
85
|
+
elements = [
|
86
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
87
|
+
element(tag_name: 'span', attributes: {class: 'foo'}),
|
88
|
+
element(tag_name: 'div', attributes: {class: 'foo'})
|
89
|
+
]
|
89
90
|
|
90
|
-
|
91
|
+
expect_all(:xpath, './/*[@class="foo"]').and_return(elements)
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
selector = {
|
94
|
+
xpath: './/*[@class="foo"]',
|
95
|
+
tag_name: 'span'
|
96
|
+
}
|
96
97
|
|
97
|
-
|
98
|
+
expect(locate_one(selector).tag_name).to eq 'span'
|
98
99
|
end
|
99
100
|
|
100
|
-
it
|
101
|
+
it 'handles custom attributes' do
|
101
102
|
elements = [
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
element(tag_name: 'div', attributes: {custom_attribute: 'foo'}),
|
104
|
+
element(tag_name: 'span', attributes: {custom_attribute: 'foo'}),
|
105
|
+
element(tag_name: 'div', attributes: {custom_attribute: 'foo'})
|
105
106
|
]
|
106
107
|
|
107
|
-
expect_one(:xpath, "
|
108
|
+
expect_one(:xpath, ".//*[local-name()='span'][@custom-attribute='foo']").and_return(elements[1])
|
108
109
|
|
109
110
|
selector = {
|
110
|
-
|
111
|
-
|
111
|
+
custom_attribute: 'foo',
|
112
|
+
tag_name: 'span'
|
112
113
|
}
|
113
114
|
|
114
115
|
expect(locate_one(selector).tag_name).to eq 'span'
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
|
-
describe
|
119
|
-
it
|
120
|
-
expect_one :xpath, "
|
121
|
-
locate_one tag_name:
|
122
|
-
text:
|
119
|
+
describe 'with special cased selectors' do
|
120
|
+
it 'normalizes space for :text' do
|
121
|
+
expect_one :xpath, ".//*[local-name()='div'][normalize-space()='foo']"
|
122
|
+
locate_one tag_name: 'div',
|
123
|
+
text: 'foo'
|
123
124
|
end
|
124
125
|
|
125
126
|
it "handles 'text' key when it's a string" do
|
126
|
-
expect_one :xpath, "
|
127
|
-
locate_one tag_name:
|
128
|
-
|
127
|
+
expect_one :xpath, ".//*[local-name()='div'][normalize-space()='foo']"
|
128
|
+
locate_one tag_name: 'div',
|
129
|
+
'text' => 'foo'
|
129
130
|
end
|
130
131
|
|
131
|
-
it
|
132
|
-
expect_one :xpath, "
|
132
|
+
it 'translates :caption to :text' do
|
133
|
+
expect_one :xpath, ".//*[local-name()='div'][normalize-space()='foo']"
|
133
134
|
|
134
|
-
locate_one tag_name:
|
135
|
-
caption:
|
135
|
+
locate_one tag_name: 'div',
|
136
|
+
caption: 'foo'
|
136
137
|
end
|
137
138
|
|
138
|
-
it
|
139
|
-
expect_one :xpath, "
|
139
|
+
it 'handles data-* attributes' do
|
140
|
+
expect_one :xpath, ".//*[local-name()='div'][@data-name='foo']"
|
140
141
|
|
141
|
-
locate_one tag_name:
|
142
|
-
data_name:
|
142
|
+
locate_one tag_name: 'div',
|
143
|
+
data_name: 'foo'
|
143
144
|
end
|
144
145
|
|
145
|
-
it
|
146
|
-
expect_one :xpath, "
|
146
|
+
it 'handles aria-* attributes' do
|
147
|
+
expect_one :xpath, ".//*[local-name()='div'][@aria-label='foo']"
|
147
148
|
|
148
|
-
locate_one tag_name:
|
149
|
-
aria_label:
|
149
|
+
locate_one tag_name: 'div',
|
150
|
+
aria_label: 'foo'
|
150
151
|
end
|
151
152
|
|
152
153
|
it "doesn't modify attribute name when the attribute key is a string" do
|
153
|
-
expect_one :xpath, "
|
154
|
+
expect_one :xpath, ".//*[local-name()='div'][@_ngcontent-c24]"
|
154
155
|
|
155
|
-
locate_one tag_name:
|
156
|
-
|
156
|
+
locate_one tag_name: 'div',
|
157
|
+
'_ngcontent-c24' => true
|
157
158
|
end
|
158
159
|
|
159
|
-
it
|
160
|
-
expect_one :xpath, "
|
160
|
+
it 'normalizes space for the :href attribute' do
|
161
|
+
expect_one :xpath, ".//*[local-name()='a'][normalize-space(@href)='foo']"
|
161
162
|
|
162
163
|
selector = {
|
163
|
-
tag_name:
|
164
|
-
href:
|
164
|
+
tag_name: 'a',
|
165
|
+
href: 'foo'
|
165
166
|
}
|
166
167
|
|
167
168
|
locate_one selector, Watir::Anchor.attributes
|
168
169
|
end
|
169
170
|
|
170
|
-
it
|
171
|
+
it 'wraps :type attribute with translate() for upper case values' do
|
171
172
|
translated_type = "translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"
|
172
|
-
expect_one :xpath, "
|
173
|
+
expect_one :xpath, ".//*[local-name()='input'][#{translated_type}='file']"
|
173
174
|
|
174
175
|
selector = [
|
175
|
-
:tag_name,
|
176
|
-
:type
|
176
|
+
:tag_name, 'input',
|
177
|
+
:type, 'file'
|
177
178
|
]
|
178
179
|
|
179
180
|
locate_one selector, Watir::Input.attributes
|
@@ -181,30 +182,33 @@ describe Watir::Locators::Element::Locator do
|
|
181
182
|
|
182
183
|
it "uses the corresponding <label>'s @for attribute or parent::label when locating by label" do
|
183
184
|
translated_type = "translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"
|
184
|
-
|
185
|
+
xpath = ".//*[local-name()='input'][#{translated_type}='text' and " \
|
186
|
+
"(@id=//label[normalize-space()='foo']/@for or " \
|
187
|
+
"parent::label[normalize-space()='foo'])]"
|
188
|
+
expect_one :xpath, xpath
|
185
189
|
|
186
190
|
selector = [
|
187
|
-
:tag_name,
|
188
|
-
:type
|
189
|
-
:label
|
191
|
+
:tag_name, 'input',
|
192
|
+
:type, 'text',
|
193
|
+
:label, 'foo'
|
190
194
|
]
|
191
195
|
|
192
196
|
locate_one selector, Watir::Input.attributes
|
193
197
|
end
|
194
198
|
|
195
|
-
it
|
196
|
-
expect_one :xpath, "
|
199
|
+
it 'uses label attribute if it is valid for element' do
|
200
|
+
expect_one :xpath, ".//*[local-name()='option'][@label='foo']"
|
197
201
|
|
198
|
-
selector = {
|
202
|
+
selector = {tag_name: 'option', label: 'foo'}
|
199
203
|
locate_one selector, Watir::Option.attributes
|
200
204
|
end
|
201
205
|
|
202
|
-
it
|
203
|
-
expect_one :xpath, "
|
206
|
+
it 'translates ruby attribute names to content attribute names' do
|
207
|
+
expect_one :xpath, ".//*[local-name()='meta'][@http-equiv='foo']"
|
204
208
|
|
205
209
|
selector = {
|
206
|
-
tag_name:
|
207
|
-
http_equiv:
|
210
|
+
tag_name: 'meta',
|
211
|
+
http_equiv: 'foo'
|
208
212
|
}
|
209
213
|
|
210
214
|
locate_one selector, Watir::Meta.attributes
|
@@ -213,28 +217,28 @@ describe Watir::Locators::Element::Locator do
|
|
213
217
|
end
|
214
218
|
end
|
215
219
|
|
216
|
-
describe
|
217
|
-
it
|
220
|
+
describe 'with regexp selectors' do
|
221
|
+
it 'handles selector with tag name and a single regexp attribute' do
|
218
222
|
elements = [
|
219
|
-
element(tag_name:
|
220
|
-
element(tag_name:
|
223
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
224
|
+
element(tag_name: 'div', attributes: {class: 'foob'})
|
221
225
|
]
|
222
226
|
|
223
|
-
expect_all(:xpath, "(
|
227
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'oob')]").and_return(elements)
|
224
228
|
|
225
|
-
expect(locate_one(tag_name:
|
229
|
+
expect(locate_one(tag_name: 'div', class: /oob/)).to eq elements[1]
|
226
230
|
end
|
227
231
|
|
228
|
-
it
|
232
|
+
it 'handles :tag_name, :index and a single regexp attribute' do
|
229
233
|
elements = [
|
230
|
-
element(tag_name:
|
231
|
-
element(tag_name:
|
234
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
235
|
+
element(tag_name: 'div', attributes: {class: 'foo'})
|
232
236
|
]
|
233
237
|
|
234
|
-
expect_all(:xpath, "(
|
238
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'foo')]").and_return(elements)
|
235
239
|
|
236
240
|
selector = {
|
237
|
-
tag_name:
|
241
|
+
tag_name: 'div',
|
238
242
|
class: /foo/,
|
239
243
|
index: 1
|
240
244
|
}
|
@@ -242,10 +246,10 @@ describe Watir::Locators::Element::Locator do
|
|
242
246
|
expect(locate_one(selector)).to eq elements[1]
|
243
247
|
end
|
244
248
|
|
245
|
-
it
|
249
|
+
it 'handles :xpath and :index selectors' do
|
246
250
|
elements = [
|
247
|
-
element(tag_name:
|
248
|
-
element(tag_name:
|
251
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
252
|
+
element(tag_name: 'div', attributes: {class: 'foo'})
|
249
253
|
]
|
250
254
|
|
251
255
|
expect_all(:xpath, './/div[@class="foo"]').and_return(elements)
|
@@ -258,10 +262,10 @@ describe Watir::Locators::Element::Locator do
|
|
258
262
|
expect(locate_one(selector)).to eq elements[1]
|
259
263
|
end
|
260
264
|
|
261
|
-
it
|
265
|
+
it 'handles :css and :index selectors' do
|
262
266
|
elements = [
|
263
|
-
element(tag_name:
|
264
|
-
element(tag_name:
|
267
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
268
|
+
element(tag_name: 'div', attributes: {class: 'foo'})
|
265
269
|
]
|
266
270
|
|
267
271
|
expect_all(:css, 'div[class="foo"]').and_return(elements)
|
@@ -274,63 +278,63 @@ describe Watir::Locators::Element::Locator do
|
|
274
278
|
expect(locate_one(selector)).to eq elements[1]
|
275
279
|
end
|
276
280
|
|
277
|
-
it
|
281
|
+
it 'handles mix of string and regexp attributes' do
|
278
282
|
elements = [
|
279
|
-
element(tag_name:
|
280
|
-
element(tag_name:
|
283
|
+
element(tag_name: 'div', attributes: {dir: 'foo', title: 'bar'}),
|
284
|
+
element(tag_name: 'div', attributes: {dir: 'foo', title: 'baz'})
|
281
285
|
]
|
282
286
|
|
283
|
-
expect_all(:xpath, "(
|
287
|
+
expect_all(:xpath, "(.//*[local-name()='div'][@dir='foo'])[contains(@title, 'baz')]").and_return(elements)
|
284
288
|
|
285
289
|
selector = {
|
286
|
-
tag_name:
|
287
|
-
dir:
|
290
|
+
tag_name: 'div',
|
291
|
+
dir: 'foo',
|
288
292
|
title: /baz/
|
289
293
|
}
|
290
294
|
|
291
295
|
expect(locate_one(selector)).to eq elements[1]
|
292
296
|
end
|
293
297
|
|
294
|
-
it
|
298
|
+
it 'handles data-* attributes with regexp' do
|
295
299
|
elements = [
|
296
|
-
element(tag_name:
|
297
|
-
element(tag_name:
|
300
|
+
element(tag_name: 'div', attributes: {'data-automation-id': 'foo'}),
|
301
|
+
element(tag_name: 'div', attributes: {'data-automation-id': 'bar'})
|
298
302
|
]
|
299
303
|
|
300
|
-
expect_all(:xpath, "(
|
304
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@data-automation-id, 'bar')]").and_return(elements)
|
301
305
|
|
302
306
|
selector = {
|
303
|
-
tag_name:
|
307
|
+
tag_name: 'div',
|
304
308
|
data_automation_id: /bar/
|
305
309
|
}
|
306
310
|
|
307
311
|
expect(locate_one(selector)).to eq elements[1]
|
308
312
|
end
|
309
313
|
|
310
|
-
it
|
314
|
+
it 'handles :label => /regexp/ selector' do
|
311
315
|
label_elements = [
|
312
|
-
element(tag_name:
|
313
|
-
element(tag_name:
|
316
|
+
element(tag_name: 'label', text: 'foo', attributes: {'for' => 'bar'}),
|
317
|
+
element(tag_name: 'label', text: 'foob', attributes: {'for' => 'baz'})
|
314
318
|
]
|
315
|
-
div_elements = [element(tag_name:
|
319
|
+
div_elements = [element(tag_name: 'div')]
|
316
320
|
|
317
|
-
expect_all(:tag_name,
|
318
|
-
expect_one(:xpath, "
|
321
|
+
expect_all(:tag_name, 'label').ordered.and_return(label_elements)
|
322
|
+
expect_one(:xpath, ".//*[local-name()='div'][@id='baz']").ordered.and_return(div_elements.first)
|
319
323
|
|
320
324
|
allow(browser).to receive(:ensure_context).and_return(nil)
|
321
325
|
allow(browser).to receive(:execute_script).and_return('foo', 'foob')
|
322
326
|
|
323
|
-
expect(locate_one(tag_name:
|
327
|
+
expect(locate_one(tag_name: 'div', label: /oob/)).to eq div_elements.first
|
324
328
|
end
|
325
329
|
|
326
|
-
it
|
327
|
-
expect_all(:tag_name,
|
328
|
-
expect(locate_one(tag_name:
|
330
|
+
it 'returns nil when no label matching the regexp is found' do
|
331
|
+
expect_all(:tag_name, 'label').and_return([])
|
332
|
+
expect(locate_one(tag_name: 'div', label: /foo/)).to be_nil
|
329
333
|
end
|
330
334
|
|
331
|
-
it
|
332
|
-
element1 = element(tag_name:
|
333
|
-
element2 = element(tag_name:
|
335
|
+
it 'relocates an element that goes stale during filtering' do
|
336
|
+
element1 = element(tag_name: 'div', attributes: {class: 'foo'})
|
337
|
+
element2 = element(tag_name: 'div', attributes: {class: 'foob'})
|
334
338
|
|
335
339
|
elements1 = [element1.clone, element2.clone]
|
336
340
|
elements2 = [element1.clone, element2.clone]
|
@@ -343,18 +347,18 @@ describe Watir::Locators::Element::Locator do
|
|
343
347
|
end
|
344
348
|
end
|
345
349
|
|
346
|
-
it
|
350
|
+
it 'finds all if :index is given' do
|
347
351
|
# or could we use XPath indeces reliably instead?
|
348
352
|
elements = [
|
349
|
-
element(tag_name:
|
350
|
-
element(tag_name:
|
353
|
+
element(tag_name: 'div'),
|
354
|
+
element(tag_name: 'div')
|
351
355
|
]
|
352
356
|
|
353
|
-
expect_all(:xpath, "
|
357
|
+
expect_all(:xpath, ".//*[local-name()='div'][@dir='foo']").and_return(elements)
|
354
358
|
|
355
359
|
selector = {
|
356
|
-
tag_name:
|
357
|
-
dir:
|
360
|
+
tag_name: 'div',
|
361
|
+
dir: 'foo',
|
358
362
|
index: 1
|
359
363
|
}
|
360
364
|
|
@@ -362,179 +366,180 @@ describe Watir::Locators::Element::Locator do
|
|
362
366
|
end
|
363
367
|
|
364
368
|
it "returns nil if found element didn't match the selector tag_name" do
|
365
|
-
expect_all(:xpath,
|
369
|
+
expect_all(:xpath, '//div').and_return([element(tag_name: 'div')])
|
366
370
|
|
367
371
|
selector = {
|
368
|
-
tag_name:
|
369
|
-
xpath:
|
372
|
+
tag_name: 'input',
|
373
|
+
xpath: '//div'
|
370
374
|
}
|
371
375
|
|
372
376
|
expect(locate_one(selector, Watir::Input.attributes)).to be_nil
|
373
377
|
end
|
374
378
|
|
375
|
-
describe
|
376
|
-
it
|
377
|
-
expect { locate_one(tag_name:
|
378
|
-
|
379
|
+
describe 'errors' do
|
380
|
+
it 'raises a TypeError if :index is not a Integer' do
|
381
|
+
expect { locate_one(tag_name: 'div', index: 'bar') }.to \
|
382
|
+
raise_error(TypeError, %(expected Integer, got "bar":String))
|
379
383
|
end
|
380
384
|
|
381
|
-
it
|
385
|
+
it 'raises a TypeError if selector value is not a String, Regexp or Boolean' do
|
382
386
|
num_type = RUBY_VERSION[/^\d+\.(\d+)/, 1].to_i >= 4 ? 'Integer' : 'Fixnum'
|
383
|
-
|
384
|
-
|
387
|
+
msg = %(expected one of [Array, String, Regexp, TrueClass, FalseClass, Symbol], got 123:#{num_type})
|
388
|
+
expect { locate_one(tag_name: 123) }
|
389
|
+
.to raise_error TypeError, msg
|
385
390
|
end
|
386
391
|
end
|
387
392
|
end
|
388
393
|
|
389
|
-
describe
|
390
|
-
describe
|
394
|
+
describe 'finds several elements' do
|
395
|
+
describe 'by delegating to Selenium' do
|
391
396
|
SELENIUM_SELECTORS.each do |loc|
|
392
397
|
it "delegates to Selenium's #{loc} locator" do
|
393
|
-
expect_all(loc,
|
398
|
+
expect_all(loc, 'bar').and_return([element(tag_name: 'div')])
|
394
399
|
match = %i[link link_text partial_link_text].include?(loc) ? :to : :to_not
|
395
400
|
msg = /:#{loc} locator is deprecated\. Use :visible_text instead/
|
396
|
-
expect { locate_all loc =>
|
401
|
+
expect { locate_all loc => 'bar' }.send(match, output(msg).to_stdout_from_any_process)
|
397
402
|
end
|
398
403
|
end
|
399
404
|
end
|
400
405
|
|
401
|
-
describe
|
402
|
-
it
|
406
|
+
describe 'with an empty selector' do
|
407
|
+
it 'finds all when an empty selctor is given' do
|
403
408
|
expect_all :xpath, './/*'
|
404
409
|
locate_all({})
|
405
410
|
end
|
406
411
|
end
|
407
412
|
|
408
|
-
describe
|
409
|
-
it
|
410
|
-
expect_all :xpath, "
|
411
|
-
locate_all tag_name:
|
412
|
-
dir:
|
413
|
+
describe 'with selectors not supported by Selenium' do
|
414
|
+
it 'handles selector with tag name and a single attribute' do
|
415
|
+
expect_all :xpath, ".//*[local-name()='div'][@dir='foo']"
|
416
|
+
locate_all tag_name: 'div',
|
417
|
+
dir: 'foo'
|
413
418
|
end
|
414
419
|
|
415
|
-
it
|
416
|
-
expect_all :xpath, "
|
417
|
-
locate_all [:tag_name,
|
418
|
-
:dir
|
419
|
-
:title
|
420
|
+
it 'handles selector with tag name and multiple attributes' do
|
421
|
+
expect_all :xpath, ".//*[local-name()='div'][@dir='foo' and @title='bar']"
|
422
|
+
locate_all [:tag_name, 'div',
|
423
|
+
:dir, 'foo',
|
424
|
+
:title, 'bar']
|
420
425
|
end
|
421
426
|
|
422
|
-
it
|
423
|
-
expect_all :xpath,
|
427
|
+
it 'handles selector with class attribute presence' do
|
428
|
+
expect_all :xpath, './/*[@class]'
|
424
429
|
|
425
430
|
locate_all class: true
|
426
431
|
end
|
427
432
|
|
428
|
-
it
|
429
|
-
|
433
|
+
it 'handles selector with multiple classes in array' do
|
434
|
+
xpath = ".//*[(contains(concat(' ', @class, ' '), ' a ') and contains(concat(' ', @class, ' '), ' b '))]"
|
435
|
+
expect_all :xpath, xpath
|
430
436
|
|
431
|
-
locate_all class: [
|
437
|
+
locate_all class: %w[a b]
|
432
438
|
end
|
433
439
|
|
434
|
-
it
|
440
|
+
it 'handles selector with multiple classes in string' do
|
435
441
|
expect_all :xpath, ".//*[contains(concat(' ', @class, ' '), ' a b ')]"
|
436
442
|
|
437
|
-
expect { locate_all class:
|
443
|
+
expect { locate_all class: 'a b' }.to have_deprecated_class_array
|
438
444
|
end
|
439
445
|
end
|
440
446
|
|
441
|
-
describe
|
442
|
-
it
|
447
|
+
describe 'with regexp selectors' do
|
448
|
+
it 'handles selector with tag name and a single regexp attribute' do
|
443
449
|
elements = [
|
444
|
-
element(tag_name:
|
445
|
-
element(tag_name:
|
446
|
-
element(tag_name:
|
447
|
-
element(tag_name:
|
450
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
451
|
+
element(tag_name: 'div', attributes: {class: 'foob'}),
|
452
|
+
element(tag_name: 'div', attributes: {class: 'doob'}),
|
453
|
+
element(tag_name: 'div', attributes: {class: 'noob'})
|
448
454
|
]
|
449
455
|
|
450
|
-
expect_all(:xpath, "(
|
451
|
-
expect(locate_all(tag_name:
|
456
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'oob')]").and_return(elements)
|
457
|
+
expect(locate_all(tag_name: 'div', class: /oob/)).to eq elements.last(3)
|
452
458
|
end
|
453
459
|
|
454
|
-
it
|
460
|
+
it 'handles mix of string and regexp attributes' do
|
455
461
|
elements = [
|
456
|
-
element(tag_name:
|
457
|
-
element(tag_name:
|
458
|
-
element(tag_name:
|
462
|
+
element(tag_name: 'div', attributes: {dir: 'foo', title: 'bar'}),
|
463
|
+
element(tag_name: 'div', attributes: {dir: 'foo', title: 'baz'}),
|
464
|
+
element(tag_name: 'div', attributes: {dir: 'foo', title: 'bazt'})
|
459
465
|
]
|
460
466
|
|
461
|
-
expect_all(:xpath, "(
|
467
|
+
expect_all(:xpath, "(.//*[local-name()='div'][@dir='foo'])[contains(@title, 'baz')]").and_return(elements)
|
462
468
|
|
463
469
|
selector = {
|
464
|
-
tag_name:
|
465
|
-
dir:
|
470
|
+
tag_name: 'div',
|
471
|
+
dir: 'foo',
|
466
472
|
title: /baz/
|
467
473
|
}
|
468
474
|
|
469
475
|
expect(locate_all(selector)).to eq elements.last(2)
|
470
476
|
end
|
471
477
|
|
472
|
-
context
|
473
|
-
it
|
478
|
+
context 'and xpath' do
|
479
|
+
it 'converts a leading run of regexp literals to a contains() expression' do
|
474
480
|
elements = [
|
475
|
-
element(tag_name:
|
476
|
-
element(tag_name:
|
477
|
-
element(tag_name:
|
481
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
482
|
+
element(tag_name: 'div', attributes: {class: 'foob'}),
|
483
|
+
element(tag_name: 'div', attributes: {class: 'bar'})
|
478
484
|
]
|
479
485
|
|
480
|
-
expect_all(:xpath, "(
|
486
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'fo')]").and_return(elements.first(2))
|
481
487
|
|
482
|
-
expect(locate_one(tag_name:
|
488
|
+
expect(locate_one(tag_name: 'div', class: /fo.b$/)).to eq elements[1]
|
483
489
|
end
|
484
490
|
|
485
|
-
it
|
491
|
+
it 'converts a trailing run of regexp literals to a contains() expression' do
|
486
492
|
elements = [
|
487
|
-
element(tag_name:
|
488
|
-
element(tag_name:
|
493
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
494
|
+
element(tag_name: 'div', attributes: {class: 'foob'})
|
489
495
|
]
|
490
496
|
|
491
|
-
expect_all(:xpath, "(
|
497
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'b')]").and_return(elements.last(1))
|
492
498
|
|
493
|
-
expect(locate_one(tag_name:
|
499
|
+
expect(locate_one(tag_name: 'div', class: /^fo.b/)).to eq elements[1]
|
494
500
|
end
|
495
501
|
|
496
|
-
it
|
502
|
+
it 'converts a leading and a trailing run of regexp literals to a contains() expression' do
|
497
503
|
elements = [
|
498
|
-
element(tag_name:
|
499
|
-
element(tag_name:
|
504
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
505
|
+
element(tag_name: 'div', attributes: {class: 'foob'})
|
500
506
|
]
|
501
507
|
|
502
|
-
expect_all(:xpath, "(
|
503
|
-
and_return(elements.last(1))
|
508
|
+
expect_all(:xpath, "(.//*[local-name()='div'])[contains(@class, 'fo') and contains(@class, 'b')]")
|
509
|
+
.and_return(elements.last(1))
|
504
510
|
|
505
|
-
expect(locate_one(tag_name:
|
511
|
+
expect(locate_one(tag_name: 'div', class: /fo.b/)).to eq elements[1]
|
506
512
|
end
|
507
513
|
|
508
|
-
it
|
514
|
+
it 'does not try to convert case insensitive expressions' do
|
509
515
|
elements = [
|
510
|
-
element(tag_name:
|
511
|
-
element(tag_name:
|
516
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
517
|
+
element(tag_name: 'div', attributes: {class: 'foob'})
|
512
518
|
]
|
513
519
|
|
514
|
-
expect_all(:xpath, "
|
520
|
+
expect_all(:xpath, ".//*[local-name()='div']").and_return(elements.last(1))
|
515
521
|
|
516
|
-
expect(locate_one(tag_name:
|
522
|
+
expect(locate_one(tag_name: 'div', class: /FOOB/i)).to eq elements[1]
|
517
523
|
end
|
518
524
|
|
519
525
|
it "does not try to convert expressions containing '|'" do
|
520
526
|
elements = [
|
521
|
-
element(tag_name:
|
522
|
-
element(tag_name:
|
527
|
+
element(tag_name: 'div', attributes: {class: 'foo'}),
|
528
|
+
element(tag_name: 'div', attributes: {class: 'foob'})
|
523
529
|
]
|
524
530
|
|
525
|
-
expect_all(:xpath, "
|
531
|
+
expect_all(:xpath, ".//*[local-name()='div']").and_return(elements.last(1))
|
526
532
|
|
527
|
-
expect(locate_one(tag_name:
|
533
|
+
expect(locate_one(tag_name: 'div', class: /x|b/)).to eq elements[1]
|
528
534
|
end
|
529
535
|
end
|
530
536
|
end
|
531
537
|
|
532
|
-
describe
|
533
|
-
it
|
534
|
-
expect { locate_all(tag_name:
|
535
|
-
|
538
|
+
describe 'errors' do
|
539
|
+
it 'raises ArgumentError if :index is given' do
|
540
|
+
expect { locate_all(tag_name: 'div', index: 1) }.to \
|
541
|
+
raise_error(ArgumentError, "can't locate all elements by :index")
|
536
542
|
end
|
537
543
|
end
|
538
544
|
end
|
539
|
-
|
540
545
|
end
|