Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poltergeist Stripe checkout.js

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>
like image 941
parov Avatar asked Mar 20 '14 17:03

parov


2 Answers

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.

like image 100
parov Avatar answered Sep 22 '22 09:09

parov


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
like image 38
PoloniculMov Avatar answered Sep 21 '22 09:09

PoloniculMov