-
- Notifications
You must be signed in to change notification settings - Fork 2k
Description
Was there a change to how variable scope is handled in the recent upgrade?
We test a massive API with several endpoints, which we reuse in several tests. Therefore, we have written down our endpoints and their requests in feature files that are separate from the tests that invoke them.
E.g. An endpoint would be documented as shown below, in a separate feature file:
endpoints/titles.feature
Feature: titles Background: Given path 'titles' @get Scenario: Get titles When method getThis endpoint feature file is invoked by another test feature file, which actually tests this endpoint.
tests/titles.feature
Feature: titles Background: Given url baseURLOCCAPI Scenario: GET standard response When def getResponse = call read('classpath:endpoints/titles.feature@get') Then match getResponse.responseStatus == 200 And match each getResponse.response.titles == { code: '#string', name: '#string' }This separation works beautifully, since data specific to the test (request body, params, user login, assertions) lives in the test feature file, while the endpoint can be reused across several tests (even negative tests). This separation works in v1.2.0. Once I run the test, variables such as the url in the test file are passed to the invoked feature file just as they are. In fact, this behaviour is as described in the documentation here.
When I ran my tests in 1.3.0, I was shocked to see all of them fail. The reason was because the url parameter defined as part of the background here wasn't passed to the invoked request. The same applies to auth tokens and other request parameters - the scope of the parent feature file seems unavailable to the invoked one.
@ptrthomas - Am I missing something here? I was also surprised to not read about this in the release notes. Also, I'd love for you to comment on the design-pattern (or anti-pattern) of separating enpoints and requests from tests.