【问题标题】:Poltergeist capybara view testing taking long time when running all test in spec in ruby on railsPoltergeist capybara 认为在 ruby​​ on rails 中运行规范中的所有测试时测试需要很长时间
【发布时间】:2016-05-03 13:22:07
【问题描述】:

我正在使用 capybara 和 poltergeist 在 ruby​​ on rails 中进行 rspec 测试。

我们正在使用条带作为支付网关。

在已存根中的条带化请求和真正的 http 连接被禁用。

但是当我单独运行规范文件时。

它通过了以下测试结果。


可以将帐单信息添加到我的帐户

在 14.27 秒内完成(文件加载需要 4.84 秒) 1 个示例,0 次失败


但是当我运行所有测试时,由于响应时间延迟很长,它失败了,我得到了这个输出。

失败

我的代码-

scenario "Can add billing information to my account", js: true do
    within "#top-menu" do
      click_link "ACCOUNT"
    end
    click_link "Billing"

    click_link "Add billing information"

    within "#subscription" do
      fill_in "Name", with: "John Smith"
      fill_in "Email", with: "john.smith@example.com"
      fill_in "Phone number", with: "0443 123123"
      fill_in "Company", with: "Cribber"
      fill_in "Street address", with: "14 Somewhere Street"
      fill_in "City", with: "Brisbane"
      fill_in "Postcode / Zip", with: "4000"
      fill_in "State", with: "QLD"
      select "Australia", from: "Country"
      select "Australian Dollar", from: "Currency"

      fill_in "Card number", with: "4242424242424242"
      select Time.now.year + 1, from: "card_expiry_year"
      fill_in "CVC", with: "123"

      check "subscription_billing_attributes_terms_of_service"
    end

    click_button "Subscribe"
    expect(page).to have_content("Thank you for subscribing to Cribber!")
  end

我在click_button“订阅”之后添加了sleep(200)。但它显示了以下结果。

有人可以帮忙吗?

提前感谢您的帮助。

我尝试在 .env.test 文件中将 http://localhost 更改为 http://127.0.0.1,但出现这些错误。

奇怪的是,如果我单独运行规范文件或查看规范的功能文件夹,那么我不会收到错误消息并且测试通过。但是如果我运行

rspec spec/ 则测试失败。

谁能帮忙?

【问题讨论】:

    标签: ruby-on-rails rspec capybara rspec-rails poltergeist


    【解决方案1】:

    您的屏幕截图中似乎解释了错误 - 虽然 localhost 和 127.0.0.1 指向同一个地方,但它们在技术上是不同的来源。您需要找到设置应用程序的位置以向 http://localhost/... 发出请求并将其更改为 127.0.0.1

    【讨论】:

    • 如果你得到完全相同的错误,那么它仍然从 localhost 请求,而你实际上并没有修复你的错误
    • @waliulBariAdnan 我不知道您在 .env.test 文件中更改了什么,但从您的图片来看,错误并不完全相同 - 主机名现在匹配但端口不允许- 你需要阅读 CORS - 并确保在 /admin/billing 上监听的任何内容都允许来自它们发出的 url 的请求。
    • ,谢谢。我更改了 DEFAULT_HOST=127.0.0.1.I 检查 rack-cors gem。但是它会破坏 Web 应用程序的安全性吗?
    • 如果你改变它不仅仅是为了测试环境它可以 - 但如果你只在测试环境中改变它,那么没有
    猜你喜欢
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多