Header 如何在behat测试中设置请求头?
我正在开发一个RESTAPI,并使用Behat和mink-selenium2-driver(第一次)对其进行测试。出于安全目的,每个调用都需要在请求头中包含一个apikey 我的问题是,我无法设置标题。我的测试如下所示:Header 如何在behat测试中设置请求头?,header,request,behat,Header,Request,Behat,我正在开发一个RESTAPI,并使用Behat和mink-selenium2-driver(第一次)对其进行测试。出于安全目的,每个调用都需要在请求头中包含一个apikey 我的问题是,我无法设置标题。我的测试如下所示: Given I add "X_ApiKey" header equal to "test" When I send a GET request to "/notice" Then the response status code should be 200 但我一直得到403
Given I add "X_ApiKey" header equal to "test"
When I send a GET request to "/notice"
Then the response status code should be 200
但我一直得到403分
任何解决方案?在硒中是不可能的。 需要在其他驾驶员身上测试,比如guzzle 据我所知,selenium驱动程序使用的是chrome,但不是它的工作原理。在我看来,检查使用其他驱动程序(如guzzle)的提议是一个答案,您可以在其中设置标题 不,我发现你可以另外选择。建议您使用代理向浏览器生成的请求注入额外的头 要做到这一点,我发现 *您应该使用包含
behatch/rest
上下文的软件包
但是,selenium驱动程序只应在您特别需要浏览器时使用,例如javascript。在这种情况下,在测试API端点时,使用浏览器只会降低速度,不会带来任何好处 可以使用微框架,它可以帮助在Behat中进行RESTful API测试。它支持使用Behat和Guzzle进行行为驱动的API测试
以下是一个例子:
Given that "X_ApiKey" header is set to "test"
When I request "/notice"
Then the response status code should be 200
以下是另一个例子:
这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论-您可以随时在自己的帖子上发表评论,一旦您有足够的评论,您就可以。@DBD修改起始假设是一种解决方案。据我所知,selenium驱动程序使用的是chrome,但不是它的工作原理。在我看来,检查使用其他驱动程序(如guzzle)的提议是一个答案,您可以在其中设置标题。特别是在他测试Pi的时候——我也这么做,但是由于这个限制,我用了GUZZLE。
Scenario: One with more `q` should be selected, q = 1 when not defined
Given that "Accept" header is set to "application/json;q=0.8,application/xml"
When I request "/examples/_003_multiformat/bmi"
Then the response status code should be 200
And the response is XML
And the type is "array"