【问题标题】:Tests failing in Capybara Webkit driver which work in Selenium Driver在 Selenium 驱动程序中工作的 Capybara Webkit 驱动程序中的测试失败
【发布时间】:2014-05-18 21:41:37
【问题描述】:

我有以下 rspec 测试,它在默认 Selenium 驱动程序中运行良好,但在 Capybara Webkit 驱动程序中失败。

单击“注册”按钮后,它会使用支付网关验证信用卡是否有效,然后再将表单发送到服务器。似乎它没有以无头模式将ajax请求发送到支付网关。我如何为 webkit 驱动程序解决这个问题,因为我知道代码是正确的,因为在 Selenium 中通过了相同的测试。

it "Subscribe to Plan", js: true do
  visit subscription_plans_path
  fill_in "user_email", :with => subscription_user_email
  fill_in "user_password", :with => "password"
  fill_in "Name", :with => "John Doe"
  fill_in "new_credit_card_field", :with => "4242424242424242"
  fill_in "security_code", :with => "123"
  select (Time.zone.now.year + 1), :from => "date_year"
  click_button "Sign up"

  page.should have_content('Dashboard')
end

【问题讨论】:

  • 在没有更多上下文的情况下很难回答这个问题。您从测试中收到的特定失败消息将是一个很好的起点。
  • 这里失败了:page.should have_content('Dashboard') 失败的原因是当你点击注册时它应该向支付网关发出ajax请求验证信用卡然后提交将表单发送到服务器,当表单提交时,他们应该转到仪表板,在那里我验证页面上应该有内容文本仪表板。我检查了测试数据库,它甚至没有提交表单,因为外部 ajax 请求可能在无头模式下被阻止。
  • 原因很可能是在您做出断言时ajax 请求尚未完成。见这里:robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
  • 如果您使用:webkit_debug 作为驱动程序而不是:webkit 运行,它将打印驱动程序的命令和结果,这应该说明它是如何与外部服务交互的。

标签: ruby-on-rails rspec capybara integration-testing capybara-webkit


【解决方案1】:

您最好的选择是使用 Selenium 驱动程序而不是使用 Webkit 驱动程序进行 javascript 相关测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 2014-08-22
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多