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

Sne*_*kla 3 dsl karate

我正在尝试运行一些测试,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         | 
Run Code Online (Sandbox Code Playgroud)

如果响应代码是200,那么它应该运行命令“ * call read('Delete.feature')”,如果responseCode400,那么它应该跳过这个命令。

有人可以帮我吗?

Pet*_*mas 7

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

Then assert responseStatus == 200 || responseStatus == 400
And if (responseStatus == 400) karate.call('delete.feature')
Run Code Online (Sandbox Code Playgroud)

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

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