Skip to content

Instantly share code, notes, and snippets.

@keoghpe
Last active August 29, 2019 10:51
Show Gist options
  • Save keoghpe/4dda25418709c2a82c23093e73544ba6 to your computer and use it in GitHub Desktop.
Save keoghpe/4dda25418709c2a82c23093e73544ba6 to your computer and use it in GitHub Desktop.
Stripe Element Capybara Utils
module StripeElementsUtils
def fill_stripe_elements(card_number)
fill_stripe_element do
card_number.to_s.chars.each do |piece|
find_field('cardnumber').send_keys(piece)
end
find_field('exp-date').send_keys("0122")
find_field('cvc').send_keys '123'
find_field('postal').send_keys '19335'
end
end
def fill_in_card(card_number)
fill_stripe_element do
number_field = find_field('cardnumber')
card_number.to_s.chars.each do |piece|
number_field.send_keys(piece)
end
end
end
def clear_card
fill_stripe_element do
find_field('cardnumber').native.clear
end
end
def fill_in_ccv(ccv)
fill_stripe_element {find_field('cvc').send_keys ccv}
end
def clear_ccv
fill_stripe_element {find_field('cvc').native.clear}
end
def fill_stripe_element
using_wait_time(15) do
within_frame(:css, '#card_element > div > iframe') do
yield
end
end
end
def expect_price_to_be(expected_price)
expect(page).to have_css("#purchase_total_value", text: expected_price)
end
def check_box_and_expect_price_to_be(expected_price, label)
find(:label, label).click
expect_price_to_be(expected_price)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment