【发布时间】:2017-07-27 19:56:45
【问题描述】:
Selenium 不支持此代码
$statusCode = $this->getSession()->getStatusCode();
是否可以通过其他方式检查状态?
【问题讨论】:
Selenium 不支持此代码
$statusCode = $this->getSession()->getStatusCode();
是否可以通过其他方式检查状态?
【问题讨论】:
这不是 Selenium 的设计目的。他们的一位项目成员reply to request to implement this in Selenium said:
我们不会将此功能添加到 WebDriver API,因为它超出了我们当前的范围(模拟用户操作)。
解决方案是使用另一个支持状态码的驱动程序,或者尝试实施一种可用的 hack(在other stack overflow questions asking the very same thing 中给出)。
【讨论】:
您可以使用Restler,这是一个支持使用 Behat 和 Guzzle 进行行为驱动 API 测试的微框架。
例如(见:status_codes.feature):
@restler
Feature: HTTP Status Codes
Scenario: I should be able to suppress status code 404
When I request "/examples/_001_helloworld?suppress_response_codes=true"
Then the response status code should be 200
【讨论】: