Search code examples
cucumbercapybarapoltergeist

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


I want to test whether some URLs are broken or not.

Now I just assert some words I know are on these pages. I feel this isn't the best that i can do. Any help?


Solution

  • I figured it out,
    You Can detect "500 Internal Server Error" using poltergeist

    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.

    so, this will work :

    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