spec/watirspec/elements/element_spec.rb in watir-6.9.1 vs spec/watirspec/elements/element_spec.rb in watir-6.10.0
- old
+ new
@@ -69,10 +69,31 @@
it "returns the value of a aria-* attribute" do
expect(browser.p.aria_label).to eq "ruby-library"
end
end
+ describe "visible text" do
+ it "finds elements by visible text" do
+ browser.goto WatirSpec.url_for('non_control_elements.html')
+
+ expect(browser.link(visible_text: "all visible")).to exist
+ expect(browser.link(visible_text: /all visible/)).to exist
+ expect(browser.link(visible_text: "some visible")).to exist
+ expect(browser.link(visible_text: /some visible/)).to exist
+ expect(browser.link(visible_text: "none visible")).not_to exist
+ expect(browser.link(visible_text: /none visible/)).not_to exist
+
+ expect(browser.link(visible_text: "Link 2", class: "external")).to exist
+ expect(browser.link(visible_text: /Link 2/, class: "external")).to exist
+
+ expect(browser.element(visible_text: "all visible")).to exist
+ expect(browser.element(visible_text: /all visible/)).to exist
+ expect(browser.element(visible_text: "some visible")).to exist
+ expect(browser.element(visible_text: /some visible/)).to exist
+ end
+ end
+
describe "finding with unknown tag name" do
it "finds an element without arguments" do
expect(browser.element).to exist
end
@@ -82,20 +103,10 @@
it "finds an element by arbitrary attribute" do
expect(browser.element(title: "no title")).to exist
end
- it "raises MissingWayOfFindingObjectException if the attribute is invalid for the element type" do
- expect {
- browser.element(for: "no title").exists?
- }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
-
- expect {
- browser.element(value: //).exists?
- }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
- end
-
it "finds several elements by xpath" do
expect(browser.elements(xpath: "//a").length).to eq 1
end
it "finds several elements by arbitrary attribute" do
@@ -189,13 +200,15 @@
it "raises UnknownObjectException exception if the element is stale" do
wd_element = browser.text_field(id: "new_user_email").wd
# simulate element going stale during lookup
- allow(browser.driver).to receive(:find_element).with(:id, 'new_user_email') { wd_element }
+ allow(browser.driver).to receive(:find_element).with(:css, '#new_user_email') { wd_element }
+ allow(browser.driver).to receive(:find_elements).with(:css, '#new_user_email') { [wd_element] }
+ allow(browser.driver).to receive(:find_elements).with(:tag_name, 'iframe') { [] }
browser.refresh
- expect { browser.text_field(id: 'new_user_email').visible? }.to raise_unknown_object_exception
+ expect { browser.text_field(css: '#new_user_email').visible? }.to raise_unknown_object_exception
end
it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do
expect(browser.div(id: "visible_child")).to be_visible
end