Reputation: 11
I have a get request which returns 404 when running via karate framework but the same request returns 200 on postman.
Sample Get request - test/messageid
message id is coming from another call to a feature file and I’m adding that in get request path.
The url is also formed proper but it still gives me 404 and the same url, when I paste on postman works totally fine and gives me 200.
What can be the reason ?
I tried to directly declare get request path like - /test/abx-188-abkl
When I hard code the request id in path, it gives me 200 in karate but if this values is dynamically generated by calling another feature file, it gives me 404.
This is so strange.
Upvotes: 1
Views: 132
Reputation: 773
First approach: Combine both scenarios into one
Feature: Json server crud test
Background: api end point url
* url 'http://localhost:3000/posts'
Scenario: get created post details
Given request {"title": "json-server","author": "typicode"}
When method post
Then status 201
And def postId = response.id
And path postId
When method get
Then status 200
Second approach: Calling a feature file inside background section using call once to avoid multiple calls
Feature: Calling Feature
Background:
* def result = callonce read('CalledFile.feature')
* def postId = result.response.id
Scenario: get created post details
Given url 'http://localhost:3000/posts'
And path postId
When method get
Then status 200
Upvotes: 1