我的测试设置是 Rspec + Capybara 和 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
最佳答案
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 可能会根据地区以及您是否运行 headless Chrome 而发生很大变化。使用 save_and_open_screenshot
可以帮助确定您的确切场景。
关于ruby-on-rails - Rspec + Capybara - Paypal Express 沙盒结帐时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49832391/