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 wo
I could not get any of the solutions here so far to work for me, and then reading this post: https://gist.github.com/nruth/b2500074749e9f56e0b7 I realized that the key was to add a delay to the test to give the Stripe enough time to 1) load the checkout window and 2) process the token.
For that reason the only code that I could get to work was this (feel free to play with timing) :
SELENIUM
describe "test stripe" do, js: true, driver: :selenium do
before do
... # fill in order form or whatever
click_button "checkout_with_stripe"
sleep(2) # allows stripe_checkout_app frame to load
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
page.execute_script(%Q{ $('input#email').val('jamesdd9302@yahoo.com'); })
page.execute_script(%Q{ $('input#card_number').val('4242424242424242'); })
page.execute_script(%Q{ $('input#cc-exp').val('08/44'); })
page.execute_script(%Q{ $('input#cc-csc').val('999'); })
page.execute_script(%Q{ $('#submitButton').click(); })
sleep(3) # allows stripe_checkout_app to submit
end
end
it "should successfully process the request" do
... # test should pass
end
end
For Capybara-webkit, the sleep
trick didn't work nor sadly did @Ryan's solution, and I got too tired of trying to figure this out so I just stopped, but hopefully someone else will get it because I'd rather use webkit for speed reasons! (I was using capybara-webkit 1.3.0
)
In case it helps, here are my relevant versions:
selenium-webdriver 2.35.1
rspec-rails 2.14.2
capybara 2.1.0
stripe 1.16.0 da216fd
rails 4.1.1
ruby 2.1.2