如何使用 Capybara 检测 500 Internal Server Error?

How can you detect a 500 Internal Server Error using Capybara?

我想测试一些网址是否损坏。

现在我只是断言这些页面上有一些我知道的词。我觉得这不是我能做的最好的。有帮助吗?

我想通了,
您可以使用 poltergeist

检测 “500 内部服务器错误”

Inspecting network traffic
You can inspect the network traffic (i.e. what resources have been loaded) on the current page by calling page.driver.network_traffic. This returns an array of request objects. A request object has a response_parts method containing data about the response chunks.

所以,这会起作用:

page.driver.network_traffic.each do |request|
  request.response_parts.uniq(&:url).each do |response|
    puts "Error : #{response.url}" if response.status == 500
  end
end