watir 6.9.1 → 6.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/lib/watir/capabilities.rb +2 -2
- data/lib/watir/elements/element.rb +5 -3
- data/lib/watir/elements/iframe.rb +2 -2
- data/lib/watir/exception.rb +0 -1
- data/lib/watir/locators/button/locator.rb +3 -10
- data/lib/watir/locators/button/validator.rb +1 -1
- data/lib/watir/locators/cell/locator.rb +3 -5
- data/lib/watir/locators/element/locator.rb +61 -105
- data/lib/watir/locators/element/selector_builder.rb +11 -4
- data/lib/watir/locators/row/locator.rb +3 -5
- data/lib/watir/locators/text_field/locator.rb +2 -13
- data/spec/browser_spec.rb +4 -3
- data/spec/element_locator_spec.rb +50 -19
- data/spec/locator_spec_helper.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/watirspec/elements/area_spec.rb +0 -4
- data/spec/watirspec/elements/button_spec.rb +0 -4
- data/spec/watirspec/elements/checkbox_spec.rb +0 -4
- data/spec/watirspec/elements/dd_spec.rb +0 -4
- data/spec/watirspec/elements/del_spec.rb +0 -4
- data/spec/watirspec/elements/div_spec.rb +30 -8
- data/spec/watirspec/elements/divs_spec.rb +1 -1
- data/spec/watirspec/elements/dl_spec.rb +0 -4
- data/spec/watirspec/elements/dt_spec.rb +0 -4
- data/spec/watirspec/elements/element_spec.rb +25 -12
- data/spec/watirspec/elements/elements_spec.rb +11 -0
- data/spec/watirspec/elements/em_spec.rb +0 -4
- data/spec/watirspec/elements/filefield_spec.rb +0 -4
- data/spec/watirspec/elements/form_spec.rb +0 -4
- data/spec/watirspec/elements/frame_spec.rb +0 -4
- data/spec/watirspec/elements/hidden_spec.rb +0 -4
- data/spec/watirspec/elements/hn_spec.rb +0 -4
- data/spec/watirspec/elements/iframe_spec.rb +0 -4
- data/spec/watirspec/elements/image_spec.rb +0 -4
- data/spec/watirspec/elements/ins_spec.rb +0 -4
- data/spec/watirspec/elements/label_spec.rb +0 -4
- data/spec/watirspec/elements/li_spec.rb +0 -4
- data/spec/watirspec/elements/link_spec.rb +2 -5
- data/spec/watirspec/elements/links_spec.rb +1 -1
- data/spec/watirspec/elements/map_spec.rb +0 -4
- data/spec/watirspec/elements/ol_spec.rb +4 -6
- data/spec/watirspec/elements/option_spec.rb +0 -13
- data/spec/watirspec/elements/p_spec.rb +0 -4
- data/spec/watirspec/elements/pre_spec.rb +0 -4
- data/spec/watirspec/elements/radio_spec.rb +0 -4
- data/spec/watirspec/elements/select_list_spec.rb +4 -6
- data/spec/watirspec/elements/span_spec.rb +2 -5
- data/spec/watirspec/elements/spans_spec.rb +1 -1
- data/spec/watirspec/elements/strong_spec.rb +0 -4
- data/spec/watirspec/elements/table_spec.rb +6 -6
- data/spec/watirspec/elements/tbody_spec.rb +0 -5
- data/spec/watirspec/elements/td_spec.rb +2 -5
- data/spec/watirspec/elements/text_field_spec.rb +0 -4
- data/spec/watirspec/elements/tfoot_spec.rb +0 -5
- data/spec/watirspec/elements/thead_spec.rb +0 -5
- data/spec/watirspec/elements/tr_spec.rb +0 -4
- data/spec/watirspec/elements/ul_spec.rb +2 -5
- data/spec/watirspec/html/multiple_ids.html +1 -0
- data/spec/watirspec/html/non_control_elements.html +6 -1
- data/spec/watirspec/radio_set_spec.rb +0 -4
- data/watir.gemspec +1 -1
- metadata +2 -4
- data/spec/watirspec/html/ng_attributes.html +0 -59
@@ -2,15 +2,11 @@ module Watir
|
|
2
2
|
module Locators
|
3
3
|
class TextField
|
4
4
|
class Locator < Element::Locator
|
5
|
-
def locate_all
|
6
|
-
find_all_by_multiple
|
7
|
-
end
|
8
5
|
|
9
6
|
private
|
10
7
|
|
11
|
-
def
|
12
|
-
|
13
|
-
super
|
8
|
+
def using_selenium(*)
|
9
|
+
# force Watir usage
|
14
10
|
end
|
15
11
|
|
16
12
|
def matches_selector?(element, rx_selector)
|
@@ -28,13 +24,6 @@ module Watir
|
|
28
24
|
super
|
29
25
|
end
|
30
26
|
|
31
|
-
def by_id
|
32
|
-
element = super
|
33
|
-
|
34
|
-
if element && !Watir::TextField::NON_TEXT_TYPES.include?(element.attribute(:type))
|
35
|
-
element
|
36
|
-
end
|
37
|
-
end
|
38
27
|
end
|
39
28
|
end
|
40
29
|
end
|
data/spec/browser_spec.rb
CHANGED
@@ -61,8 +61,8 @@ describe Watir::Browser do
|
|
61
61
|
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
62
62
|
@opts.merge!(url: url, desired_capabilities: caps)
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
msg = /You can now pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
|
65
|
+
expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
|
66
66
|
expect(@new_browser.driver.capabilities.accept_insecure_certs).to eq true
|
67
67
|
end
|
68
68
|
end
|
@@ -104,7 +104,8 @@ describe Watir::Browser do
|
|
104
104
|
opts = {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
105
105
|
url: url}
|
106
106
|
WatirSpec.implementation.browser_args = [:remote, opts]
|
107
|
-
|
107
|
+
msg = /You can now pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
|
108
|
+
expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
|
108
109
|
server_url = @new_browser.driver.instance_variable_get('@bridge').http.instance_variable_get('@server_url')
|
109
110
|
expect(server_url).to eq URI.parse(url)
|
110
111
|
end
|
@@ -8,7 +8,9 @@ describe Watir::Locators::Element::Locator do
|
|
8
8
|
SELENIUM_SELECTORS.each do |loc|
|
9
9
|
it "delegates to Selenium's #{loc} locator" do
|
10
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
|
+
msg = /:#{loc} locator is deprecated\. Use :visible_text instead/
|
13
|
+
expect { locate_one loc => "bar" }.send(match, output(msg).to_stdout_from_any_process)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -75,7 +77,43 @@ describe Watir::Locators::Element::Locator do
|
|
75
77
|
it "handles selector with multiple classes in string" do
|
76
78
|
expect_one :xpath, ".//*[contains(concat(' ', @class, ' '), ' a b ')]"
|
77
79
|
|
78
|
-
|
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'
|
79
117
|
end
|
80
118
|
end
|
81
119
|
|
@@ -93,13 +131,6 @@ describe Watir::Locators::Element::Locator do
|
|
93
131
|
caption: "foo"
|
94
132
|
end
|
95
133
|
|
96
|
-
it "translates :class_name to :class" do
|
97
|
-
expect_one :xpath, ".//div[contains(concat(' ', @class, ' '), ' foo ')]"
|
98
|
-
|
99
|
-
locate_one tag_name: "div",
|
100
|
-
class_name: "foo"
|
101
|
-
end
|
102
|
-
|
103
134
|
it "handles data-* attributes" do
|
104
135
|
expect_one :xpath, ".//div[@data-name='foo']"
|
105
136
|
|
@@ -274,6 +305,10 @@ describe Watir::Locators::Element::Locator do
|
|
274
305
|
|
275
306
|
expect_all(:tag_name, "label").ordered.and_return(label_elements)
|
276
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
|
+
|
277
312
|
expect(locate_one(tag_name: "div", label: /oob/)).to eq div_elements.first
|
278
313
|
end
|
279
314
|
|
@@ -303,6 +338,7 @@ describe Watir::Locators::Element::Locator do
|
|
303
338
|
|
304
339
|
it "returns nil if found element didn't match the selector tag_name" do
|
305
340
|
expect_one(:xpath, "//div").and_return(element(tag_name: "div"))
|
341
|
+
expect_all(:xpath, "//div").and_return([element(tag_name: "div")])
|
306
342
|
|
307
343
|
selector = {
|
308
344
|
tag_name: "input",
|
@@ -323,14 +359,6 @@ describe Watir::Locators::Element::Locator do
|
|
323
359
|
expect { locate_one(tag_name: 123) }.to \
|
324
360
|
raise_error(TypeError, %[expected one of [Array, String, Regexp, TrueClass, FalseClass, Symbol], got 123:#{num_type}])
|
325
361
|
end
|
326
|
-
|
327
|
-
it "raises a MissingWayOfFindingObjectException if the attribute is not valid" do
|
328
|
-
bad_selector = {tag_name: "input", href: "foo"}
|
329
|
-
valid_attributes = Watir::Input.attributes
|
330
|
-
|
331
|
-
expect { locate_one(bad_selector, valid_attributes) }.to \
|
332
|
-
raise_error(Watir::Exception::MissingWayOfFindingObjectException, "invalid attribute: :href")
|
333
|
-
end
|
334
362
|
end
|
335
363
|
end
|
336
364
|
|
@@ -339,7 +367,9 @@ describe Watir::Locators::Element::Locator do
|
|
339
367
|
SELENIUM_SELECTORS.each do |loc|
|
340
368
|
it "delegates to Selenium's #{loc} locator" do
|
341
369
|
expect_all(loc, "bar").and_return([element(tag_name: "div")])
|
342
|
-
|
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)
|
343
373
|
end
|
344
374
|
end
|
345
375
|
end
|
@@ -380,7 +410,8 @@ describe Watir::Locators::Element::Locator do
|
|
380
410
|
it "handles selector with multiple classes in string" do
|
381
411
|
expect_all :xpath, ".//*[contains(concat(' ', @class, ' '), ' a b ')]"
|
382
412
|
|
383
|
-
|
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
|
384
415
|
end
|
385
416
|
end
|
386
417
|
|
data/spec/locator_spec_helper.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ require 'webdrivers'
|
|
9
9
|
require 'locator_spec_helper'
|
10
10
|
require 'rspec'
|
11
11
|
|
12
|
-
SELENIUM_SELECTORS = %i(class class_name css id tag_name xpath)
|
12
|
+
SELENIUM_SELECTORS = %i(class class_name css id tag_name xpath link_text partial_link_text link)
|
13
13
|
|
14
14
|
if ENV['RELAXED_LOCATE'] == "false"
|
15
15
|
Watir.relaxed_locate = false
|
@@ -44,10 +44,6 @@ describe "Area" do
|
|
44
44
|
it "raises TypeError when 'what' argument is invalid" do
|
45
45
|
expect { browser.area(id: 3.14).exists? }.to raise_error(TypeError)
|
46
46
|
end
|
47
|
-
|
48
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
49
|
-
expect { browser.area(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
50
|
-
end
|
51
47
|
end
|
52
48
|
|
53
49
|
# Attribute methods
|
@@ -92,10 +92,6 @@ describe "Button" do
|
|
92
92
|
it "raises TypeError when 'what' argument is invalid" do
|
93
93
|
expect { browser.button(id: 3.14).exists? }.to raise_error(TypeError)
|
94
94
|
end
|
95
|
-
|
96
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
97
|
-
expect { browser.button(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
98
|
-
end
|
99
95
|
end
|
100
96
|
|
101
97
|
# Attribute methods
|
@@ -68,10 +68,6 @@ describe "CheckBox" do
|
|
68
68
|
it "raises TypeError when 'what' argument is invalid" do
|
69
69
|
expect { browser.checkbox(id: 3.14).exists? }.to raise_error(TypeError)
|
70
70
|
end
|
71
|
-
|
72
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
73
|
-
expect { browser.checkbox(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
74
|
-
end
|
75
71
|
end
|
76
72
|
|
77
73
|
# Attribute methods
|
@@ -26,10 +26,6 @@ describe "Dd" do
|
|
26
26
|
it "raises TypeError when 'what' argument is invalid" do
|
27
27
|
expect { browser.dd(id: 3.14).exists? }.to raise_error(TypeError)
|
28
28
|
end
|
29
|
-
|
30
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
31
|
-
expect { browser.dd(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
32
|
-
end
|
33
29
|
end
|
34
30
|
|
35
31
|
# Attribute methods
|
@@ -37,10 +37,6 @@ describe "Del" do
|
|
37
37
|
it "raises TypeError when 'what' argument is invalid" do
|
38
38
|
expect { browser.del(id: 3.14).exists? }.to raise_error(TypeError)
|
39
39
|
end
|
40
|
-
|
41
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
42
|
-
expect { browser.del(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
43
|
-
end
|
44
40
|
end
|
45
41
|
|
46
42
|
# Attribute methods
|
@@ -13,12 +13,15 @@ describe "Div" do
|
|
13
13
|
expect(browser.div(id: /header/)).to exist
|
14
14
|
expect(browser.div(title: "Header and primary navigation")).to exist
|
15
15
|
expect(browser.div(title: /Header and primary navigation/)).to exist
|
16
|
-
expect(browser.div(text: "
|
17
|
-
|
16
|
+
expect(browser.div(text: "Not shownNot hidden")).to exist
|
17
|
+
msg = /text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
|
18
|
+
expect { expect(browser.div(text: /Not hidden/)).to exist }.to output(msg).to_stdout_from_any_process
|
18
19
|
expect(browser.div(class: "profile")).to exist
|
19
20
|
expect(browser.div(class: /profile/)).to exist
|
20
21
|
expect(browser.div(index: 0)).to exist
|
21
22
|
expect(browser.div(xpath: "//div[@id='header']")).to exist
|
23
|
+
expect(browser.div(custom_attribute: "custom")).to exist
|
24
|
+
expect(browser.div(custom_attribute: /custom/)).to exist
|
22
25
|
end
|
23
26
|
|
24
27
|
it "returns the first div if given no args" do
|
@@ -31,7 +34,8 @@ describe "Div" do
|
|
31
34
|
expect(browser.div(title: "no_such_title")).to_not exist
|
32
35
|
expect(browser.div(title: /no_such_title/)).to_not exist
|
33
36
|
expect(browser.div(text: "no_such_text")).to_not exist
|
34
|
-
|
37
|
+
msg = /:text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
|
38
|
+
expect { expect(browser.div(text: /no_such_text/)).to_not exist }.to output(msg).to_stdout_from_any_process
|
35
39
|
expect(browser.div(class: "no_such_class")).to_not exist
|
36
40
|
expect(browser.div(class: /no_such_class/)).to_not exist
|
37
41
|
expect(browser.div(index: 1337)).to_not exist
|
@@ -41,11 +45,6 @@ describe "Div" do
|
|
41
45
|
it "raises TypeError when 'what' argument is invalid" do
|
42
46
|
expect { browser.div(id: 3.14).exists? }.to raise_error(TypeError)
|
43
47
|
end
|
44
|
-
|
45
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
46
|
-
expect { browser.div(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
47
|
-
end
|
48
|
-
|
49
48
|
end
|
50
49
|
|
51
50
|
# Attribute methods
|
@@ -85,6 +84,11 @@ describe "Div" do
|
|
85
84
|
browser.goto WatirSpec.url_for "multiple_ids.html"
|
86
85
|
expect(browser.div(id: "multiple", class: "bar").class_name).to eq "bar"
|
87
86
|
end
|
87
|
+
|
88
|
+
it "should find the id with the correct tag name" do
|
89
|
+
browser.goto WatirSpec.url_for "multiple_ids.html"
|
90
|
+
expect(browser.span(id: "multiple").class_name).to eq "foobar"
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
describe "#style" do
|
@@ -128,6 +132,12 @@ describe "Div" do
|
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
135
|
+
describe "custom methods" do
|
136
|
+
it "returns the custom attribute if the element exists" do
|
137
|
+
expect(browser.div(custom_attribute: "custom").attribute_value("custom-attribute")).to eq "custom"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
131
141
|
describe "#respond_to?" do
|
132
142
|
it "returns true for all attribute methods" do
|
133
143
|
expect(browser.div(index: 0)).to respond_to(:class_name)
|
@@ -137,6 +147,13 @@ describe "Div" do
|
|
137
147
|
end
|
138
148
|
end
|
139
149
|
|
150
|
+
describe "Deprecation Warnings" do
|
151
|
+
it "throws deprecation when for text and RegExp" do
|
152
|
+
msg = /text locator with RegExp values to find elements based on only visible text is deprecated\. Use :visible_text instead/
|
153
|
+
expect { browser.div(text: /Not hidden/).exists? }.to output(msg).to_stdout_from_any_process
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
140
157
|
# Manipulation methods
|
141
158
|
not_compliant_on :headless do
|
142
159
|
describe "#click" do
|
@@ -152,6 +169,11 @@ describe "Div" do
|
|
152
169
|
expect { browser.div(index: 1337).click }.to raise_unknown_object_exception
|
153
170
|
expect { browser.div(xpath: "//div[@id='no_such_id']").click }.to raise_unknown_object_exception
|
154
171
|
end
|
172
|
+
|
173
|
+
it "includes custom message if element with a custom attribute does not exist" do
|
174
|
+
message = "Watir treated [\"custom_attribute\"] as a non-HTML compliant attribute, ensure that was intended"
|
175
|
+
expect { browser.div(custom_attribute: "not_there").click }.to raise_unknown_object_exception(message)
|
176
|
+
end
|
155
177
|
end
|
156
178
|
|
157
179
|
describe "#click!" do
|
@@ -26,10 +26,6 @@ describe "Dl" do
|
|
26
26
|
it "raises TypeError when 'what' argument is invalid" do
|
27
27
|
expect { browser.dl(id: 3.14).exists? }.to raise_error(TypeError)
|
28
28
|
end
|
29
|
-
|
30
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
31
|
-
expect { browser.dl(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
32
|
-
end
|
33
29
|
end
|
34
30
|
|
35
31
|
# Attribute methods
|
@@ -26,10 +26,6 @@ describe "Dt" do
|
|
26
26
|
it "raises TypeError when 'what' argument is invalid" do
|
27
27
|
expect { browser.dt(id: 3.14).exists? }.to raise_error(TypeError)
|
28
28
|
end
|
29
|
-
|
30
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
31
|
-
expect { browser.dt(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
32
|
-
end
|
33
29
|
end
|
34
30
|
|
35
31
|
# Attribute methods
|
@@ -71,6 +71,27 @@ describe "Element" do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
describe "visible text" do
|
75
|
+
it "finds elements by visible text" do
|
76
|
+
browser.goto WatirSpec.url_for('non_control_elements.html')
|
77
|
+
|
78
|
+
expect(browser.link(visible_text: "all visible")).to exist
|
79
|
+
expect(browser.link(visible_text: /all visible/)).to exist
|
80
|
+
expect(browser.link(visible_text: "some visible")).to exist
|
81
|
+
expect(browser.link(visible_text: /some visible/)).to exist
|
82
|
+
expect(browser.link(visible_text: "none visible")).not_to exist
|
83
|
+
expect(browser.link(visible_text: /none visible/)).not_to exist
|
84
|
+
|
85
|
+
expect(browser.link(visible_text: "Link 2", class: "external")).to exist
|
86
|
+
expect(browser.link(visible_text: /Link 2/, class: "external")).to exist
|
87
|
+
|
88
|
+
expect(browser.element(visible_text: "all visible")).to exist
|
89
|
+
expect(browser.element(visible_text: /all visible/)).to exist
|
90
|
+
expect(browser.element(visible_text: "some visible")).to exist
|
91
|
+
expect(browser.element(visible_text: /some visible/)).to exist
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
74
95
|
describe "finding with unknown tag name" do
|
75
96
|
it "finds an element without arguments" do
|
76
97
|
expect(browser.element).to exist
|
@@ -84,16 +105,6 @@ describe "Element" do
|
|
84
105
|
expect(browser.element(title: "no title")).to exist
|
85
106
|
end
|
86
107
|
|
87
|
-
it "raises MissingWayOfFindingObjectException if the attribute is invalid for the element type" do
|
88
|
-
expect {
|
89
|
-
browser.element(for: "no title").exists?
|
90
|
-
}.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
91
|
-
|
92
|
-
expect {
|
93
|
-
browser.element(value: //).exists?
|
94
|
-
}.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
95
|
-
end
|
96
|
-
|
97
108
|
it "finds several elements by xpath" do
|
98
109
|
expect(browser.elements(xpath: "//a").length).to eq 1
|
99
110
|
end
|
@@ -191,10 +202,12 @@ describe "Element" do
|
|
191
202
|
wd_element = browser.text_field(id: "new_user_email").wd
|
192
203
|
|
193
204
|
# simulate element going stale during lookup
|
194
|
-
allow(browser.driver).to receive(:find_element).with(:
|
205
|
+
allow(browser.driver).to receive(:find_element).with(:css, '#new_user_email') { wd_element }
|
206
|
+
allow(browser.driver).to receive(:find_elements).with(:css, '#new_user_email') { [wd_element] }
|
207
|
+
allow(browser.driver).to receive(:find_elements).with(:tag_name, 'iframe') { [] }
|
195
208
|
browser.refresh
|
196
209
|
|
197
|
-
expect { browser.text_field(
|
210
|
+
expect { browser.text_field(css: '#new_user_email').visible? }.to raise_unknown_object_exception
|
198
211
|
end
|
199
212
|
|
200
213
|
it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do
|
@@ -33,4 +33,15 @@ describe "Elements" do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
describe "visible text" do
|
37
|
+
it 'finds elements by visible text' do
|
38
|
+
browser.goto WatirSpec.url_for('non_control_elements.html')
|
39
|
+
expect(browser.links(visible_text: 'all visible').count).to eq(1)
|
40
|
+
expect(browser.links(visible_text: /all visible/).count).to eq(1)
|
41
|
+
expect(browser.links(visible_text: 'some visible').count).to eq(1)
|
42
|
+
expect(browser.links(visible_text: /some visible/).count).to eq(1)
|
43
|
+
expect(browser.links(visible_text: 'none visible').count).to eq(0)
|
44
|
+
expect(browser.links(visible_text: /none visible/).count).to eq(0)
|
45
|
+
end
|
46
|
+
end
|
36
47
|
end
|