Skip to content

Instantly share code, notes, and snippets.

@nruth
Last active March 7, 2023 00:21
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nruth/b2500074749e9f56e0b7 to your computer and use it in GitHub Desktop.
Save nruth/b2500074749e9f56e0b7 to your computer and use it in GitHub Desktop.
capybara selenium webdriver stripe.js checkout test helper
# -*- encoding : utf-8 -*-
module PayStripeHelpers
# must be used with driver: :selenium (or :sauce?)
def pay_stripe
sleep(0.7) # wait for the js to create the popup in response to pressing the button
within_frame 'stripe_checkout_app' do # must be selenium
# fill_in 'card_number', with: '4242424242424242' no longer works
4.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4242')}
# fill_in 'cc-exp', with: '5/2018' no longer works
page.driver.browser.find_element(:id, 'cc-exp').send_keys '5'
page.driver.browser.find_element(:id, 'cc-exp').send_keys '18'
page.driver.browser.find_element(:id, 'cc-csc').send_keys '123'
find('button[type="submit"]').click
end
# wait for stripe to finish and change the page; default is 2 seconds
find("body[data-tests-page='member/dashboard']", wait: 30)
end
end
if respond_to?(:World) #cucumber
World(PayStripeHelpers)
else
RSpec.configure do |config|
config.include PayStripeHelpers, :type => :feature
end
end
@hayesr
Copy link

hayesr commented Sep 17, 2018

Thanks @bhbryant!

@jmzbond
Copy link

jmzbond commented Dec 8, 2018

Is this still working for you ? It's not working for me anymore... This is what I'm seeing

  • Stripe DOES in fact initialize an iframe; without Stripe on the page, no iframe is found
  • However, with Stripe and within that iframe, if I search for a generic input element, it defaults to an input I had put on the page

It's as if Stripe's iframe is "deflecting" to my regular view...

@excid3
Copy link

excid3 commented Oct 24, 2019

I added some helpers for Stripe SCA in case anyone needs that: https://gorails.com/blog/fill-in-stripe-elements-js-for-sca-3d-secure-2-and-capybara

@jclusso
Copy link

jclusso commented Mar 7, 2023

Was wondering if there was any update to this for Stripe's Payment Element? Have been struggling to get this to work with the new way. Oddly, I can get it to work within a pry, but not when it runs by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment