5

I am developing a Rest API and testing it with Behat and mink-selenium2-driver (for the first time) . For security purposes, every call needs to contain a apikey in the request header.

My Problem is, i cannot set the header. My test looks like this:

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

But I keep getting a 403.

Any solutions?

user3210460
  • 71
  • 2
  • 4

3 Answers3

2

In selenium it is imposible. Need to test this on other driver, like guzzle

To my knowledge, selenium driver lead chrome, but not how it is working. Proposition to check of use others drivers like guzzle, where you can set headers is a answer, in my opinion.

No i found you could additionally other option. It's recommended you use a proxy to inject additional headers to the requests generated by the browser.

To do this i found * http://wiremock.org/

timiTao
  • 1,417
  • 3
  • 20
  • 34
  • 3
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – DBD Nov 13 '14 at 13:38
  • @DBD revise the starting assumptions is kind of solution. To my knowledge, selenium driver lead chrome, but not how it is working. Proposition to check of use others drivers like guzzle, where you can set headers is a answer, in my opinion. Especially where he testing RESTApi - i'm doing the same, but due to this restriction, i used GUZZLE. – timiTao Nov 20 '14 at 10:14
0

You should use the behatch package which includes a behatch/rest context.

However, the selenium driver should only be used when you specifically need a browser, for javascript for example. In this case, as you are testing a API endpoint, using a browser will only slow you down and not bring any benefit.

i.am.michiel
  • 10,281
  • 7
  • 50
  • 86
0

It's possible to use Restler, a micro framework which can help with RESTful API testing in Behat. It support behavior Driven API testing using Behat and Guzzle.

Here is the example:

Given that "X_ApiKey" header is set to "test"
When I request "/notice"
Then the response status code should be 200

Here is another example from negotiation-format.feature file:

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"
kenorb
  • 155,785
  • 88
  • 678
  • 743