Skip to content

Instantly share code, notes, and snippets.

@ckenst
Last active April 23, 2018 17:56
Show Gist options
  • Save ckenst/163d3c20233b4738ff49866c79895ef5 to your computer and use it in GitHub Desktop.
Save ckenst/163d3c20233b4738ff49866c79895ef5 to your computer and use it in GitHub Desktop.
Selenium script for filling out stripe's checkout popup modal
# This selenium script will automatically fill out stripe's checkout popup modal
# from the example modal within Stripe's documentation
require 'selenium-webdriver'
require 'rspec/expectations'
def setup
@driver = Selenium::WebDriver.for :chrome
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
run do
@driver.get 'https://stripe.com/docs/checkout'
wait = Selenium::WebDriver::Wait.new(timeout: 10)
pay_with_card_btn = @driver.find_element(css: 'button.stripe-button-el' )
wait.until { pay_with_card_btn.displayed? }
pay_with_card_btn.click
pay_modal = @driver.find_element(css: 'iframe.stripe_checkout_app' )
wait.until { pay_modal.displayed? }
@driver.switch_to.frame "stripe_checkout_app"
email = @driver.find_element(css: '.Fieldset-input.Textbox-control')
wait.until { email.displayed? }
email.send_keys 'something@something.com'
# This is where the test will fail. The modal seems to detect the automated input
# and a new panel slides over to ask for a text message input with a button to
# switch back to manual input
# Your own implementation will probably not have this functionality
credit_card = @driver.find_element(css: '.is-head-1 .Fieldset-input')
wait.until { credit_card.displayed? }
credit_card.send_keys '4242 4242 4242 4242'
expiration = @driver.find_element(css: '.Fieldset-childLeft .Fieldset-input')
wait.until { expiration.displayed? }
expiration.send_keys '02 21'
cvc = @driver.find_element(css: '.Fieldset-childRight .Fieldset-input')
wait.until { cvc.displayed? }
cvc.send_keys '123'
zip = @driver.find_element(css: '.Fieldset-childBottom .Fieldset-input')
wait.until { zip.displayed? }
zip.send_keys '12345'
pay_btn = @driver.find_element(css: 'button')
wait.until { pay_btn.displayed? }
pay_btn.click
end
@ckenst
Copy link
Author

ckenst commented Apr 23, 2018

How is this similar or different to https://gist.github.com/nruth/b2500074749e9f56e0b7? Is this a helper method?

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