imbo / behat-api-extension

API extension for Behat, used to ease testing of JSON-based APIs
MIT License
109 stars 42 forks source link

Unable to access the response before visiting a page #49

Closed mbittner closed 7 years ago

mbittner commented 7 years ago

The "Then" step in my scenario erros out saying "Unable to access the response before visiting a page". Installed it today, with composer "imbo/behat-api-extension": "^2.0",

Any idea what can cause this? I seem pretty inline with the documentation, I set my body/header prior to the When step that should actually do the HTTP GET.

Here is my scenario:

    Scenario: Test POST
      Given the request body is:
        """
        {"some":"data"}
        """
      And the "Content-Type" request header is "application/json"
      When I request "/api/performers" using HTTP GET
      Then the response status code should not be 200
mbittner commented 7 years ago

So it seems that the "Then the response status code should not be 200" do not use the same response object used by the When I request step.

The "When I request" step is define by your extension and the "response status code" is defined by the MinkContext.

Is there a way to use both step in the same scnenario?

christeredvartsen commented 7 years ago

That might be tricky. I haven't looked into Mink, so I'm not sure if it would be possible to share responses. That would require that both extensions use the same library for requests / responses though. That might actually be the case already for all I know.

imbo/behat-api-extension has a step quite similar to the Then-step you are using though:

Then the response code is :code
Then the response code is not :code
christeredvartsen commented 7 years ago

imbo/behat-api-extension uses Guzzle 6, which uses PSR-7 interfaces for requests and responses, so if Mink uses a library which also uses PSR-7 the exchange of the response should be doable.

christeredvartsen commented 7 years ago

It seems Mink itself doesn't do the actual HTTP requests, but simply forwards them to the driver in use, which might not even be written in PHP, so there isn't a feasible way to do what you're asking.

Closing this issue for now.