Search code examples
rubyrspeccapybararspec-rails

Verify the response code of the page with Capybara and Selenium


I'm trying to verify the response code of a page by using capybara. I used the expect statement as -

    expect(page.status_code).to eq(404)

I'm getting the error as -

    Capybara::NotSupportedByDriverError:
    Capybara::Driver::Base#status_code

Might be status_code is not supported by Capybara. Is there any other way to verify the status/response code or I'm doing something wrong in the expect statement.


Solution

  • The Selenium driver doesn’t support status_code because it’s not really something you should be testing in a feature/system test. The idea of feature/system tests (which Capybara is aimed at) is to test from a users perspective. Since a user cares about what is shown in the browser thatts what should be tested for rather than the status code. If you still want to test for the status code it should be done in a request spec rather than a feature/system spec