Skip to content

Commit

Permalink
within_frame should allow no arguments when theres only one frame i…
Browse files Browse the repository at this point in the history
…n scope
  • Loading branch information
twalpole committed Jul 6, 2018
1 parent 5b76480 commit d3d57d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ def switch_to_frame(frame)
scopes.slice!(idx..-1)
driver.switch_to_frame(:top)
end
else
raise ArgumentError, "You must provide a frame element, :parent, or :top when calling switch_to_frame"
end
end

Expand Down Expand Up @@ -846,6 +848,8 @@ def element_script_result(arg)
end

def _find_frame(*args)
return find(:frame) if args.length.zero?

case args[0]
when Capybara::Node::Element
args[0]
Expand Down
14 changes: 14 additions & 0 deletions lib/capybara/spec/session/frame/within_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@
end
end

it "should default to the :frame selector when no options passed" do
container = @session.find(:css, '#divInMainWindow')
@session.within(container) do
# Ensure only one frame in scope
@session.within_frame do
expect(@session).to have_css('body#parentBody')
end
end
expect {
# Multiple frames in scope here
@session.within_frame do; end
}.to raise_error Capybara::Ambiguous
end

it "should find multiple nested frames" do
@session.within_frame 'parentFrame' do
@session.within_frame 'childFrame' do
Expand Down

0 comments on commit d3d57d7

Please sign in to comment.