Use elements parent as the query scope for matches matchers when available

This commit is contained in:
Thomas Walpole 2018-07-24 07:53:16 -07:00
parent 11618a0cec
commit 6acf5df123
2 changed files with 12 additions and 1 deletions

View File

@ -709,7 +709,7 @@ module Capybara
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(query_scope)
yield query.resolve_for(self.first(:xpath, './parent::*', minimum: 0) || query_scope)
end
true
end

View File

@ -24,6 +24,17 @@ Capybara::SpecHelper.spec '#match_selector?' do
expect(@element).to match_selector('span.number')
end
it 'should work with elements located via a sibling selector' do
sibling = @element.sibling(:css, 'span', text: 'Other span')
expect(sibling).to match_selector(:xpath, '//span')
expect(sibling).to match_selector(:css, 'span')
end
it 'should work with the html element' do
html = @session.find('/html')
expect(html).to match_selector(:css, 'html')
end
context 'with text' do
it 'should discard all matches where the given string is not contained' do
expect(@element).to match_selector('//span', text: '42')