使用 Capybara 和 Selenium 验证页面的响应代码

Verify the response code of the page with Capybara and Selenium

我正在尝试使用水豚验证页面的响应代码。我将 expect 语句用作 -

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

我得到的错误是 -

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

可能 status_code 水豚不支持。有没有其他方法可以验证 status/response 代码,或者我在 expect 语句中做错了什么。

Selenium 驱动程序不支持 status_code 因为它不是您真正应该在 feature/system 测试中测试的东西。 feature/system 测试(Capybara 的目标)的想法是从用户的角度进行测试。由于用户关心浏览器中显示的内容,因此应该测试的内容而不是状态代码。如果您仍想测试状态代码,则应在请求规范中完成,而不是 feature/system 规范