From c2660fd3f0e3669d053f85c245beae359821047c Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 26 Jan 2013 13:59:34 +0000 Subject: [PATCH] Fix `within_frame` not switching context back properly Closes #242 --- README.md | 2 ++ lib/capybara/poltergeist/client/compiled/web_page.js | 8 ++++++-- lib/capybara/poltergeist/client/web_page.coffee | 7 +++++-- spec/integration/session_spec.rb | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0019d4e..01aead5 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,8 @@ Include as much information as possible. For example: * Fix timing issue when using `within_frame` that could cause errors. [Issue #183, #211] (@errm, @motemen) +* Fix bug with `within_frame` not properly switching the context back + after the block has executed. [Issue #242] ### 1.0.2 ### diff --git a/lib/capybara/poltergeist/client/compiled/web_page.js b/lib/capybara/poltergeist/client/compiled/web_page.js index 8996ac2..0c716ee 100644 --- a/lib/capybara/poltergeist/client/compiled/web_page.js +++ b/lib/capybara/poltergeist/client/compiled/web_page.js @@ -202,8 +202,12 @@ Poltergeist.WebPage = (function() { }; WebPage.prototype.pushFrame = function(name) { - this.frames.push(name); - return this["native"].switchToFrame(name); + if (this["native"].switchToFrame(name)) { + this.frames.push(name); + return true; + } else { + return false; + } }; WebPage.prototype.popFrame = function() { diff --git a/lib/capybara/poltergeist/client/web_page.coffee b/lib/capybara/poltergeist/client/web_page.coffee index 69066ff..5183494 100644 --- a/lib/capybara/poltergeist/client/web_page.coffee +++ b/lib/capybara/poltergeist/client/web_page.coffee @@ -138,8 +138,11 @@ class Poltergeist.WebPage @native.customHeaders = headers pushFrame: (name) -> - @frames.push(name) - @native.switchToFrame(name) + if @native.switchToFrame(name) + @frames.push(name) + true + else + false popFrame: -> @frames.pop() diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 752aa96..7653756 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -350,6 +350,8 @@ describe Capybara::Session do @session.current_path.should == "/poltergeist/slow" @session.html.should include('slow page') end + + @session.current_path.should == '/' end it 'waits for the cross-domain frame to load' do