Skip to content

Commit

Permalink
Merge pull request teamcapybara#969 from twalpole/within_frame
Browse files Browse the repository at this point in the history
Test and fix for within_frame issue teamcapybara#686
  • Loading branch information
jnicklas committed Feb 24, 2013
2 parents d0008e8 + 63f2495 commit b99650d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(app, options={})
@app = app
@browser = nil
@exit_status = nil
@frame_handles = {}
@options = DEFAULT_OPTIONS.merge(options)
end

Expand Down Expand Up @@ -94,12 +95,17 @@ def reset!
# @param [Capybara::Node::Base] a_node frame element
#
def within_frame(frame_handle)
@frame_handles[browser.window_handle] ||= []
frame_handle = frame_handle.native if frame_handle.is_a?(Capybara::Node::Base)
old_window = browser.window_handle
browser.switch_to.frame(frame_handle)
@frame_handles[browser.window_handle] << frame_handle
a=browser.switch_to.frame(frame_handle)
yield
ensure
browser.switch_to.window old_window
# There doesnt appear to be any way in Webdriver to move back to a parent frame
# other than going back to the root and then reiterating down
@frame_handles[browser.window_handle].pop
browser.switch_to.default_content
@frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }
end

def find_window( selector )
Expand Down
10 changes: 9 additions & 1 deletion lib/capybara/spec/session/within_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@
@session.within_frame element do
@session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
end
end
end
it "should find multiple nested frames" do
@session.within_frame 'parentFrame' do
@session.within_frame 'childFrame' do
@session.within_frame 'grandchildFrame1' do end
@session.within_frame 'grandchildFrame2' do end
end
end
end
end
9 changes: 9 additions & 0 deletions lib/capybara/spec/views/frame_child.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>This is the child frame title</title>
</head>
<body>
<iframe src="/frame_one" id="grandchildFrame1"></iframe>
<iframe src="/frame_two" id="grandchildFrame2"></iframe>
</body>
</html>
8 changes: 8 additions & 0 deletions lib/capybara/spec/views/frame_parent.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>This is the parent frame title</title>
</head>
<body>
<iframe src='/frame_child' id='childFrame'>
</body>
</html>
1 change: 1 addition & 0 deletions lib/capybara/spec/views/within_frames.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<div id="divInMainWindow">This is the text for divInMainWindow</div>
<iframe src="/frame_one" id="frameOne"></iframe>
<iframe src="/frame_two" id="frameTwo"></iframe>
<iframe src="/frame_parent" id="parentFrame"></iframe>
</body>
</html>

0 comments on commit b99650d

Please sign in to comment.