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

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

View file

@ -24,6 +24,17 @@ Capybara::SpecHelper.spec '#match_selector?' do
expect(@element).to match_selector('span.number') expect(@element).to match_selector('span.number')
end 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 context 'with text' do
it 'should discard all matches where the given string is not contained' do it 'should discard all matches where the given string is not contained' do
expect(@element).to match_selector('//span', text: '42') expect(@element).to match_selector('//span', text: '42')