Skip to content

Commit

Permalink
Workarounds for not being able to use #fragment from Nokogiri sparkle…
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed May 13, 2018
1 parent 1101b9e commit f6fa8bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 13 additions & 1 deletion lib/watigiri/locators/element/locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def locate
@query_scope.doc ||= if @query_scope.is_a?(Watir::Browser)
Nokogiri::HTML(@query_scope.html).tap { |d| d.css('script').remove }
else
Nokogiri::HTML.fragment(@query_scope.inner_html)
# This should be using `#fragment`, but can't because of
# https://github.com/sparklemotion/nokogiri/issues/572
Nokogiri::HTML(@query_scope.inner_html)
end

element = using_watir(:first)
Expand Down Expand Up @@ -92,12 +94,22 @@ class Locator < Watir::Locators::Button::Locator
class Cell
class Locator < Watir::Locators::Cell::Locator
include LocatorHelpers

# Don't use for rows
def regex?
false
end
end
end

class Row
class Locator < Watir::Locators::Row::Locator
include LocatorHelpers

# Don't use for rows
def regex?
false
end
end
end

Expand Down
9 changes: 2 additions & 7 deletions spec/watigiri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
expect(browser.li(id: /non_link_1/).text!).to eq 'Non-link 1'
expect(browser.li(title: "This is not a link!").text!).to eq 'Non-link 1'
expect(browser.li(title: /This is not a link!/).text!).to eq 'Non-link 1'
expect(browser.li(text: "Non-link 1").text!).to eq 'Non-link 1'
expect(browser.li(text: /Non-link 1/).text!).to eq 'Non-link 1'
expect(browser.li(class: "nonlink").text!).to eq 'Non-link 1'
expect(browser.li(class: /nonlink/).text!).to eq 'Non-link 1'
expect(browser.li(id: /non_link/, index: 1).text!).to eq 'Non-link 2'
Expand All @@ -26,17 +24,14 @@
end

it "locates with inner html driver call" do
div = browser.div(id: 'header')
div.exist?
div = browser.div(id: 'header').tap(&:exist?)
expect(browser.driver).to_not receive(:find_element)
expect(browser.driver).to_not receive(:find_elements)

expect(div.li(id: "non_link_1").text!).to eq 'Non-link 1'
expect(div.li(id: /non_link_1/).text!).to eq 'Non-link 1'
expect(div.li(title: "This is not a link!").text!).to eq 'Non-link 1'
expect(div.li(title: /This is not a link!/).text!).to eq 'Non-link 1'
expect(div.li(text: "Non-link 1").text!).to eq 'Non-link 1'
expect(div.li(text: /Non-link 1/).text!).to eq 'Non-link 1'
expect(div.li(class: "nonlink").text!).to eq 'Non-link 1'
expect(div.li(class: /nonlink/).text!).to eq 'Non-link 1'
expect(div.li(id: /non_link/, index: 1).text!).to eq 'Non-link 2'
Expand All @@ -56,7 +51,7 @@
end

it "locates by sub-element" do
navbar = browser.ul(id: 'navbar').tap { |el| el.exist? }
navbar = browser.ul(id: 'navbar').tap(&:exist?)
expect(browser.driver).to_not receive(:find_element)
expect(browser.driver).to_not receive(:find_elements)
expect(navbar.li(id: "non_link_1").text!).to eq "Non-link 1"
Expand Down

0 comments on commit f6fa8bd

Please sign in to comment.