如何在空手道中使用 if 条件进行动态响应代码



>我正在尝试运行一些测试,如果成功,则需要在每个场景结束时调用"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')",如果responseCode400,那么它应该跳过这个命令。

有人可以帮我解决这个问题吗?

请参考文档:https://github.com/intuit/karate#conditional-logic

Then assert responseStatus == 200 || responseStatus == 400
And if (responseStatus == 400) karate.call('delete.feature')

另外一条评论Then status responseCode- 我认为这行不通。

编辑 - 另请参阅: 使用空手道检查 2 种不同的状态

最新更新