I've hit the wall trying to write an integration test for Stripe's checkout.js [ https://checkout.stripe.com/checkout.js ] for my Rails 3.2 app.
Stripe checkout works correctly for me when manually tested (using Stripe's testing keys), but I cannot get Capybara to detect and fill_in
the email field in the Stripe checkout iframe modal.
I am using poltergeist for headless javascript, though have also tested this with capybara-webkit and even selenium with the same problem.
What I am trying to test is the complete subscription sign-up flow, to show that a new user can create a subscriber account after entering their payment details in Stripe - but I cannot get past the Stripe checkout pop-up.
Here is my before .. do
:
describe "show Stripe checkout", :js => true do
before do
visit pricing_path
click_button 'plan-illuminated'
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
fill_in "email", :with => "test-user@example.com"
fill_in "billing-name", :with => "Mr Name"
fill_in "billing-street", :with => "test Street"
fill_in "billing-zip", :with => 10000
fill_in "billing-city", :with => "Berlin"
click_button "Payment Info"
end
end
it { should have_selector('button', text: "Subscribe") }
end
Which errors with:
Failure/Error: Capybara.within_frame stripe_iframe do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":[null]}
If I swap out the attempt to choose the correct iframe (suggested here: Capybara trouble filling in JS modal ) like so:
# stripe_iframe = all('iframe[name=stripe_checkout_app]').last
# Capybara.within_frame stripe_iframe do
Capybara.within_frame 'stripe_checkout_app' do
I still get the similar:
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":["stripe_checkout_app"]}
It appears that whichever javascript testing gem I use, rspec/capybara cannot find the Stripe checkout iframe. When I check with Selenium I see the Choose this Plan
button pressed and the Checkout pop-up, but the spec times out looking for the email field to fill in.
Any ideas?
I've already tried:
- Various ways of choosing or finding the email field.
- Updating all my gems.
- Using StripeMock before this (not that it should be involved, right?).
- Running the same tests against Stripe's own site, which give the same errors:
Testing with:
visit "https://stripe.com/docs/checkout"
click_button 'Pay with Card'
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
fill_in 'Email', with: 'test@example.com'
sleep 3
end
Depending which method I use to select the iframe I receive the same errors. Using just Capybara.within_frame 'stripe_checkout_app' do
:
Failure/Error: Capybara.within_frame stripe_iframe do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":[null]}
or using Selenium with stripe_iframe = all('iframe[name=stripe_checkout_app]').last
:
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
or even just:
Failure/Error: fill_in 'Email', with: 'test@example.com'
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Email' found
...depending on which testing javascript gem I am using.
Any help or wisdom is greatly appreciated!