mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Pass scope to within
block - add click,double_click,right_click to sesion
This commit is contained in:
parent
51bca83001
commit
8520561983
3 changed files with 17 additions and 3 deletions
|
@ -40,6 +40,7 @@ module Capybara
|
|||
|
||||
NODE_METHODS = %i[
|
||||
all first attach_file text check choose scroll_to scroll_by
|
||||
click double_click right_click
|
||||
click_link_or_button click_button click_link
|
||||
fill_in find find_all find_button find_by_id find_field find_link
|
||||
has_content? has_text? has_css? has_no_content? has_no_text?
|
||||
|
@ -360,7 +361,7 @@ module Capybara
|
|||
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
|
||||
begin
|
||||
scopes.push(new_scope)
|
||||
yield if block_given?
|
||||
yield new_scope if block_given?
|
||||
ensure
|
||||
scopes.pop
|
||||
end
|
||||
|
|
|
@ -49,6 +49,19 @@ Capybara::SpecHelper.spec '#within' do
|
|||
expect { @session.text }.to raise_error(StandardError)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should pass scope element to the block' do
|
||||
@session.within(:css, '#another_foo') do |scope|
|
||||
expect(scope).to match_css('#another_foo')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should scope click', requires: [:js], focus_: true do
|
||||
@session.within(:css, '#another_foo') do |scope|
|
||||
@session.click
|
||||
expect(scope).to have_text('I was clicked')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with XPath selector' do
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="another_foo">
|
||||
<div id="another_foo" onclick="this.innerHTML = 'I was clicked';">
|
||||
<ul>
|
||||
<li>With Simple HTML: <a href="/">Go</a>
|
||||
<li>With Simple HTML: <a href="/">Go</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue