Poltergeist Stripe checkout.js
Asked Answered
R

2

7

I'm trying to test in my Rails app the Stripe checkout popup (http://www.stripe.com/checkout).

I was using Capybara + selenium-driver and everything worked well. When the page is loaded, the checkout.js adds an iframe, and I was able to access it

within_frame('stripe_checkout_app') do
 do something
end

Now, switching to Poltergeist, I get this error:

Failure/Error: within_frame('stripe_checkout_app') do Capybara::Poltergeist::FrameNotFound: The frame 'stripe_checkout_app' was not found.

and if I inspect the page, there's not iframe. So I think that this script

<script type="text/javascript" src="https://checkout.stripe.com/checkout.js"></script>

is not loaded when I run the test with Poltergeist.

Update

I tried to run the test with Capybara-webkit, with same result.

Failure/Error: Capybara.within_frame('stripe_checkout_app') do
 Capybara::Webkit::InvalidResponseError:
   Unable to locate frame.

I also tried to wait for half a minute! with

sleep 30

These are my webmock settings:

RSpec.configure { |config|
WebMock.disable_net_connect!(allow_localhost: true)
 }

Update 2:

'stripe_checkout_app' is the name of the iframe.

<iframe frameborder="0" allowtransparency="true" src="https://checkout.stripe.com/v3" name="stripe_checkout_app" class="stripe_checkout_app" style="z-index: 9999; display: none; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"></iframe>
Recommendation answered 20/3, 2014 at 17:15 Comment(0)
R
8

For anybody interested, I found a way to access the iframe without using 'within_frame', just by using the Poltergeist switch window method.

stripe = page.driver.window_handles.last

page.within_window stripe do
  fill_in "Name", :with => "Name"
  fill_in "Street", :with => "Street"
  fill_in "Postal", :with => 10000
  fill_in "City", :with => "Berlin"

  click_button "Payment Info"
end

For spanish people, I found the solution here: numerica latina.

Recommendation answered 21/3, 2014 at 13:7 Comment(3)
parov, I have the same problem ( stackoverflow.com/questions/24081305 ) though when I try your solution I get the following error: undefined method 'window_handles' for #<Capybara::Poltergeist::Driver:0x007fa09adde108> - any ideas? Thanks!Dramamine
can you check which branch of poltergeist are you using? The method is there in the master branch. github.com/teampoltergeist/poltergeist/blob/master/lib/capybara/…Recommendation
Thanks parov! You lead me down the correct path! When I bundle update I get Using poltergeist (1.0.3), which seemed pretty old. ... inspecting my gemfile shows I had locked Capybara to '~>1.1.2' which limited Poltergeist to 1.0.3. Updating everything to the latest gems (Capybara 2.3.0 & Poltergeist 1.5.1) fixed everything!Dramamine
R
2

If you have a similar issue with phantomjs 1.9.7, it's because of the SSL settings. You can disable checking using:

Capybara.register_driver :poltergeist do |app|
  options = {
    phantomjs_options: ['--ssl-protocol=any', '--ignore-ssl-errors=yes'],
    inspector: false
  }
  Capybara::Poltergeist::Driver.new(app, options)
end
Raasch answered 9/1, 2016 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.