Repository: teampoltergeist/poltergeist

Issue #166: `within_iframe` fails if the iframe requires substantial time to load
Created: 2012-10-01T23:38:47Z
Running Poltergeist 0.7.0 with PhantomJS 1.7.0, I can only access an iframe after a sleep 1 delay.
The spec code:
visit('/datasets/new')
page.within_frame('datum-iframe') do
  page.should have_content('Add file')
end

...fails with:
Failure/Error: page.within_frame('datum-iframe') do
  Capybara::Poltergeist::JavascriptError:
  One or more errors were raised in the Javascript code on the page:

  TypeError: 'undefined' is not an object (evaluating 'this.window.document')
    at /Users/marshall/.rvm/gems/ruby-1.9.3-p125@senti/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:47
    at /Users/marshall/.rvm/gems/ruby-1.9.3-p125@senti/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:56
    at /Users/marshall/.rvm/gems/ruby-1.9.3-p125@senti/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:15
    at phantomjs://webpage.evaluate():2
    at phantomjs://webpage.evaluate():3
    at phantomjs://webpage.evaluate():3
    at phantomjs://webpage.evaluate():3

If I add a sleep to the spec code:
visit('/datasets/new')
sleep 1
page.within_frame('datum-iframe') do
  page.should have_content('Add file')
end

...then it passes.
I've found that if the iframe src is set to a URL that loads instantly, then no sleep is required to pass.
It seems that the within_iframe method does not perform correctly if the iframe requires substantial time to load.

Duplicate issue #159: Support iframes
Created: 2012-09-21T08:53:21Z
Iframe support seems not to work for me. Doing this:
within_frame('preview') { page.text }
results in an exception:
NoMethodError: undefined method `strip' for nil:NilClass

I can provide a test case for this, If you'll need one

Closing comment (2012-10-06T23:35:37Z): My gem 'poltergeist' line points directly to jonleighton/poltergeist.
@jonleighton Yes, the issue appears to be the same as #166 – I've just waited for a couple of seconds (within a pry session) before inspecting:
within_frame('preview') { page.text }

...and it worked good!
If you don't wait – the issue's still reproducible, but the error this time is new:
[1] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_5>)> within_frame('preview') { page.text }
Capybara::Poltergeist::JavascriptError: One or more errors were raised in the Javascript code on the page:

TypeError: 'undefined' is not an object (evaluating 'this.window.document')
    at /Users/gmile/.rvm/gems/ruby-1.9.3-p194@nywt/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:40
    at /Users/gmile/.rvm/gems/ruby-1.9.3-p194@nywt/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:52
    at /Users/gmile/.rvm/gems/ruby-1.9.3-p194@nywt/gems/poltergeist-0.7.0/lib/capybara/poltergeist/client/compiled/agent.js:15
    at phantomjs://webpage.evaluate():2
    at phantomjs://webpage.evaluate():3
    at phantomjs://webpage.evaluate():3
    at phantomjs://webpage.evaluate():3
from /Users/gmile/.rvm/gems/ruby-1.9.3-p194@nywt/gems/poltergeist-0.7.0/lib/capybara/poltergeist/browser.rb:143:in `command'