如何在空手道中使用 if 条件进行动态响应代码
How to use if condition in Karate for dynamic responseCodes
我正在尝试 运行 几个需要在每个场景结束时调用“Delete.feature
”文件的测试,如果它是成功的,但如果它是失败测试,那么它不应该调用“Delete.feature
”文件。
我的测试看起来像这样:
Given url ApiAdminURL
And path AdminPath
And header apigateway-apikey = apiGatewayKey
And header apigateway-basepath = 'lambdaTest'
* json myReq = read('users.json')
* set myReq.apiConf.subscriptionTiers = subscriptionTiers
* print 'my subscriptions : ', myReq.apiConf
And request myReq
When method post
Then status responseCode
* call read('Delete.feature')
Examples:
| subscriptionTiers |responseCode|
| [Unlimited,Gold,Bronze, Silver] |200 |
| [Unlimited,Gold,Bronze] |200 |
| [Unlimited,Gold,BronzeAuto-Approved] |400 |
如果响应代码是 200
,那么它应该 运行 命令“* call read('Delete.feature')
”,如果 responseCode
是 400
,那么它应该跳过这个命令。
有人可以帮我解决这个问题吗?
请参考文档:https://github.com/intuit/karate#conditional-logic
Then assert responseStatus == 200 || responseStatus == 400
And eval if (responseStatus == 400) karate.call('delete.feature')
另外一条评论,Then status responseCode
- 我认为这行不通。
编辑 - 另见:
我正在尝试 运行 几个需要在每个场景结束时调用“Delete.feature
”文件的测试,如果它是成功的,但如果它是失败测试,那么它不应该调用“Delete.feature
”文件。
我的测试看起来像这样:
Given url ApiAdminURL
And path AdminPath
And header apigateway-apikey = apiGatewayKey
And header apigateway-basepath = 'lambdaTest'
* json myReq = read('users.json')
* set myReq.apiConf.subscriptionTiers = subscriptionTiers
* print 'my subscriptions : ', myReq.apiConf
And request myReq
When method post
Then status responseCode
* call read('Delete.feature')
Examples:
| subscriptionTiers |responseCode|
| [Unlimited,Gold,Bronze, Silver] |200 |
| [Unlimited,Gold,Bronze] |200 |
| [Unlimited,Gold,BronzeAuto-Approved] |400 |
如果响应代码是 200
,那么它应该 运行 命令“* call read('Delete.feature')
”,如果 responseCode
是 400
,那么它应该跳过这个命令。
有人可以帮我解决这个问题吗?
请参考文档:https://github.com/intuit/karate#conditional-logic
Then assert responseStatus == 200 || responseStatus == 400
And eval if (responseStatus == 400) karate.call('delete.feature')
另外一条评论,Then status responseCode
- 我认为这行不通。
编辑 - 另见: