Created
June 28, 2019 14:57
-
-
Save webuilder240/d8f504269705437b0817136f7371deaf to your computer and use it in GitHub Desktop.
This file contains 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 payjp's checkout popup modal | |
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://pay.jp/docs/started' | |
wait = Selenium::WebDriver::Wait.new(timeout: 10) | |
pay_with_card_btn = @driver.find_element(css: '#payjp_checkout_box > input[type=button]:nth-child(1)' ) | |
wait.until { pay_with_card_btn.displayed? } | |
pay_with_card_btn.click | |
pay_modal = @driver.find_element(css: 'iframe#payjp-checkout-iframe' ) | |
wait.until { pay_modal.displayed? } | |
@driver.switch_to.frame "payjp-checkout-iframe" | |
# 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: '#payjp_cardNumber') | |
wait.until { credit_card.displayed? } | |
credit_card.send_keys '4242 4242 4242 4242' | |
expiration_month = @driver.find_element(css: '#payjp_cardExpiresMonth') | |
wait.until { expiration_month.displayed? } | |
expiration_month.send_keys '02' | |
expiration_year = @driver.find_element(css: '#payjp_cardExpiresYear') | |
wait.until { expiration_year.displayed? } | |
expiration_year.send_keys '21' | |
cvc = @driver.find_element(css: '#payjp_cardCvc') | |
wait.until { cvc.displayed? } | |
cvc.send_keys '123' | |
card_name = @driver.find_element(css: '#payjp_cardName') | |
wait.until { card_name.displayed? } | |
card_name.send_keys 'YUI ARAGAKI' | |
pay_btn = @driver.find_element(css: '#payjp_cardSubmit') | |
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