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