我有一个 get 请求,通过空手道框架运行时返回 404,但相同的请求在邮递员上返回 200。
获取请求示例 - test/messageid
消息 ID 来自对功能文件的另一次调用,我将其添加到获取请求路径中。
网址也形成正确,但它仍然给我 404 和相同的网址,当我粘贴到邮递员上时工作完全正常并给我 200。
可能是什么原因?
我尝试直接声明获取请求路径,如 - /test/abx-188-abkl
当我在路径中硬编码请求 ID 时,它在空手道中给我 200,但如果该值是通过调用另一个功能文件动态生成的,它会给我 404。
这太奇怪了。
第一种方法:将两种场景合并为一个
Feature: Json server crud test
Scenario: get created post details
Given url 'http://localhost:3000/posts'
And request {"title": "json-server","author": "typicode"}
When method post
Then status 201
And def postId = response.id
Given url 'http://localhost:3000/posts'
And path postId
When method get
Then status 200
第二种方法:使用一次调用来调用后台部分中的特征文件,以避免多次调用
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