1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Default to document when element has no parent in match selector query

This commit is contained in:
Thomas Walpole 2018-09-10 12:47:14 -07:00
parent b635aa3e94
commit 6971ac6967
4 changed files with 15 additions and 2 deletions

View file

@ -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 # Version 3.7.1
Release date: 2018-09-05 Release date: 2018-09-05

View file

@ -713,7 +713,7 @@ module Capybara
query_args = _set_query_session_options(*query_args) query_args = _set_query_session_options(*query_args)
query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block) query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
synchronize(query.wait) do 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 end
true true
end end

View file

@ -364,7 +364,7 @@ module Capybara
# @overload switch_to_frame(element) # @overload switch_to_frame(element)
# @param [Capybara::Node::Element] iframe/frame element to switch to # @param [Capybara::Node::Element] iframe/frame element to switch to
# @overload switch_to_frame(:parent) # @overload switch_to_frame(:parent)
# Switch to the parent element # Switch to the parent frame
# @overload switch_to_frame(:top) # @overload switch_to_frame(:top)
# Switch to the top level document # Switch to the top level document
# #

View file

@ -22,4 +22,10 @@ Capybara::SpecHelper.spec '#match_css?' do
expect(@element).to match_css('span') { |el| el[:class] == 'number' } expect(@element).to match_css('span') { |el| el[:class] == 'number' }
expect(@element).not_to match_css('span') { |el| el[:class] == 'not_number' } expect(@element).not_to match_css('span') { |el| el[:class] == 'not_number' }
end 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 end