Skip to content

Commit

Permalink
Default to document when element has no parent in match selector query
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Sep 10, 2018
1 parent 60c0251 commit ef292c8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 3.7.2
Release date: unreleased

### Fixed

* Fix MatchQuery based matchers when used on a root element found using any type of parent/ancestor query - Issue #2097

# Version 3.7.1
Release date: 2018-09-05

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def _verify_match_result(query_args, optional_filter_block)
query_args = _set_query_session_options(*query_args)
query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
synchronize(query.wait) do
yield query.resolve_for(first(:xpath, './parent::*', minimum: 0) || query_scope)
yield query.resolve_for(first(:xpath, './parent::*', minimum: 0) || session&.document || query_scope)
end
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def within_table(locator)
# @overload switch_to_frame(element)
# @param [Capybara::Node::Element] iframe/frame element to switch to
# @overload switch_to_frame(:parent)
# Switch to the parent element
# Switch to the parent frame
# @overload switch_to_frame(:top)
# Switch to the top level document
#
Expand Down
6 changes: 6 additions & 0 deletions lib/capybara/spec/session/element/match_css_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
expect(@element).to match_css('span') { |el| el[:class] == 'number' }
expect(@element).not_to match_css('span') { |el| el[:class] == 'not_number' }
end

it 'should work with root element found via ancestor' do
el = @session.find(:css, 'body').find(:xpath, '..')
expect(el).to match_css('html')
expect { expect(el).to not_match_css('html') }.to raise_exception(RSpec::Expectations::ExpectationNotMetError)
end
end

0 comments on commit ef292c8

Please sign in to comment.