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 fdba4e1921
commit 84a69f3d8e
2 changed files with 12 additions and 1 deletions

View file

@ -726,7 +726,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')