Skip to content

Commit

Permalink
Merge pull request teamcapybara#1110 from twalpole/iframe
Browse files Browse the repository at this point in the history
Push nil scope when switching windows and frames to fix issue 1103
  • Loading branch information
jnicklas committed Jul 2, 2013
2 parents 519bbb1 + 5ff8575 commit 7d2733d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,12 @@ def within_table(locator)
# @param [String] name name of a frame
#
def within_frame(frame_handle)
scopes.push(nil)
driver.within_frame(frame_handle) do
yield
end
ensure
scopes.pop
end

##
Expand All @@ -276,7 +279,10 @@ def within_frame(frame_handle)
# @param [String] handle of the window
#
def within_window(handle, &blk)
scopes.push(nil)
driver.within_window(handle, &blk)
ensure
scopes.pop
end

##
Expand Down Expand Up @@ -383,7 +389,7 @@ def has_no_title?(content)
end

def current_scope
scopes.last
scopes.last || document
end

private
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/within_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@
end
end
end
it "should reset scope when changing frames" do
@session.within(:css, '#divInMainWindow') do
@session.within_frame 'parentFrame' do
@session.has_selector?(:css, "iframe#childFrame").should be_true
end
end
end
end
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/within_window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@
end
@session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
end
it "should reset scope when switching windows" do
@session.within(:css, '#divInMainWindow') do
@session.within_window("secondPopup") do
@session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
end
end
end
end

0 comments on commit 7d2733d

Please sign in to comment.