Last active
April 23, 2018 17:56
-
-
Save ckenst/163d3c20233b4738ff49866c79895ef5 to your computer and use it in GitHub Desktop.
Selenium script for filling out stripe's checkout popup modal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 '[email protected]' | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How is this similar or different to https://gist.github.com/nruth/b2500074749e9f56e0b7? Is this a helper method?