Rspec + Capybara - Paypal Express 沙盒结账时间
Rspec + Capybara - Paypal Express Sandbox checkout timing
我的测试设置是 Rspec + Capybara with Poltergeist / Phantomjs。
我正在尝试测试 Paypal express 沙箱 - 有时测试通过,有时不通过。看起来像是时间问题。
这是我的测试代码段,它会重定向到 Paypal,并在成功后返回到我的页面。我在沙盒帐户上使用我的信用卡,因此没有信用卡处理...
有人对此有有效的设置或任何建议吗?
# confirm order and proceed / redirect to paypal
find('button#booking-button').click
using_wait_time(60) do
# login on paypal express sandbox page
within_frame(find('iframe')) do
fill_in 'email', with: Rails.application.secrets.paypal_test_user_email
fill_in 'password', with: Rails.application.secrets.paypal_test_user_password
find('button#btnLogin').click
end
using_wait_time(60) do
# confirm payment and redirect back to my page
find('input#confirmButtonTop').click
using_wait_time(60) do
# check if element on my page exists
expect(page).to have_selector('div#checkout-thank-you')
end
end
end
看起来他们改变了布局。表单而不是 iframe。这有时对我有用:
find('button#booking-button').click
using_wait_time(60) do
within('form.proceed.maskable') do
fill_in 'email', with: Rails.application.secrets.paypal_test_user_email
fill_in 'password', with: Rails.application.secrets.paypal_test_user_password
find('button#btnLogin').click
end
using_wait_time(60) do
find('input#confirmButtonTop').click
using_wait_time(60) do
expect(page).to have_selector('div#checkout-thank-you')
end
end
end
这取决于API您使用的是什么。
对于 REST API (v1),以下对我有用:
# click client side checkout button
paypal_window =
window_opened_by do
within_frame(find('.paypal-button iframe')) do
find('.paypal-button-text').click
end
end
# pay within popup window
within_window(paypal_window) do
click_link 'Log In'
# I am assuming you have a buyer email/password in the sandbox set up
fill_in 'login_email', with: MyConfig['paypal_buyer_email']
click_on 'Next'
fill_in 'password', with: MyConfig['paypal_buyer_password']
click_on 'Log In'
click_on 'Pay Now'
end
在撰写本文时(对于旧的 SOAP API 而不是较新的 REST API),这是可行的:
click_link 'Log In'
using_wait_time(60) do
fill_in 'login_email', with: 'email'
click_on 'btnNext'
fill_in 'password', with: 'password'
click_on 'btnLogin'
click_on 'confirmButtonTop'
end
Jack Kinsella 的回答为我们服务了 2 年 (),但 PayPal 最近更新了他们在欧洲的 UI。
您可以以访客身份登录,但测试信用卡很麻烦,因为它们会不断过期并且填写表格需要更长的时间。您现在首先必须接受 cookie 并表明您要登录。
def pay_with_paypal
paypal_window =
window_opened_by do
within_frame(find(".paypal-buttons iframe")) do
first(".paypal-button").click
end
end
within_window(paypal_window) do
# similar, just couple of extra steps and calling reusable method for details
Capybara.using_wait_time(5) do
# accept cookies
click_button("Accept Cookies") if page.has_button?("Accept Cookies")
# switch to login form (if needed)
click_on("Log In") if page.has_content?("PayPal Guest Checkout")
add_paypal_login_details
click_on("Pay Now")
end
end
end
def add_paypal_login_details
fill_in "login_email", with: "youraccount@test.com"
click_on "Next"
fill_in "login_password", with: "yourpassword"
find("#btnLogin").click
end
我发现 PayPal 可能会根据地区以及您是否 运行 无头 Chrome 发生很大变化。使用 save_and_open_screenshot
可以帮助确定您的确切情况。
我的测试设置是 Rspec + Capybara with Poltergeist / Phantomjs。
我正在尝试测试 Paypal express 沙箱 - 有时测试通过,有时不通过。看起来像是时间问题。
这是我的测试代码段,它会重定向到 Paypal,并在成功后返回到我的页面。我在沙盒帐户上使用我的信用卡,因此没有信用卡处理...
有人对此有有效的设置或任何建议吗?
# confirm order and proceed / redirect to paypal
find('button#booking-button').click
using_wait_time(60) do
# login on paypal express sandbox page
within_frame(find('iframe')) do
fill_in 'email', with: Rails.application.secrets.paypal_test_user_email
fill_in 'password', with: Rails.application.secrets.paypal_test_user_password
find('button#btnLogin').click
end
using_wait_time(60) do
# confirm payment and redirect back to my page
find('input#confirmButtonTop').click
using_wait_time(60) do
# check if element on my page exists
expect(page).to have_selector('div#checkout-thank-you')
end
end
end
看起来他们改变了布局。表单而不是 iframe。这有时对我有用:
find('button#booking-button').click
using_wait_time(60) do
within('form.proceed.maskable') do
fill_in 'email', with: Rails.application.secrets.paypal_test_user_email
fill_in 'password', with: Rails.application.secrets.paypal_test_user_password
find('button#btnLogin').click
end
using_wait_time(60) do
find('input#confirmButtonTop').click
using_wait_time(60) do
expect(page).to have_selector('div#checkout-thank-you')
end
end
end
这取决于API您使用的是什么。
对于 REST API (v1),以下对我有用:
# click client side checkout button
paypal_window =
window_opened_by do
within_frame(find('.paypal-button iframe')) do
find('.paypal-button-text').click
end
end
# pay within popup window
within_window(paypal_window) do
click_link 'Log In'
# I am assuming you have a buyer email/password in the sandbox set up
fill_in 'login_email', with: MyConfig['paypal_buyer_email']
click_on 'Next'
fill_in 'password', with: MyConfig['paypal_buyer_password']
click_on 'Log In'
click_on 'Pay Now'
end
在撰写本文时(对于旧的 SOAP API 而不是较新的 REST API),这是可行的:
click_link 'Log In'
using_wait_time(60) do
fill_in 'login_email', with: 'email'
click_on 'btnNext'
fill_in 'password', with: 'password'
click_on 'btnLogin'
click_on 'confirmButtonTop'
end
Jack Kinsella 的回答为我们服务了 2 年 (),但 PayPal 最近更新了他们在欧洲的 UI。
您可以以访客身份登录,但测试信用卡很麻烦,因为它们会不断过期并且填写表格需要更长的时间。您现在首先必须接受 cookie 并表明您要登录。
def pay_with_paypal
paypal_window =
window_opened_by do
within_frame(find(".paypal-buttons iframe")) do
first(".paypal-button").click
end
end
within_window(paypal_window) do
# similar, just couple of extra steps and calling reusable method for details
Capybara.using_wait_time(5) do
# accept cookies
click_button("Accept Cookies") if page.has_button?("Accept Cookies")
# switch to login form (if needed)
click_on("Log In") if page.has_content?("PayPal Guest Checkout")
add_paypal_login_details
click_on("Pay Now")
end
end
end
def add_paypal_login_details
fill_in "login_email", with: "youraccount@test.com"
click_on "Next"
fill_in "login_password", with: "yourpassword"
find("#btnLogin").click
end
我发现 PayPal 可能会根据地区以及您是否 运行 无头 Chrome 发生很大变化。使用 save_and_open_screenshot
可以帮助确定您的确切情况。