嘿空手道DSL社区-我想知道是否有人可以根据先前的响应值(条件逻辑)来帮助我了解如何在方案中执行特定的测试步骤。阅读文档后,我发现使用功能部件文件可以实现此目的,但我也想知道如何在方案中优雅地做到这一点。
我将尝试在下面解释我要实现的目标。
Given path '/games/list'
When method get
Then status 200
And def response = {"games":[{"gameId":"3431572","gameStatus":"RELEASED","releaseDate":"2018-10-31"}]}
And match response.games == '#[]'
Given path '/games/action'
And request {"game":{"gameId":"3431572","gameStatus":"RELEASED","releaseDate":"2018-10-31"},"gameAction":"DOWNLOAD"}
When method post
Then status 200
如果response.game.gameStatus == 'UNRELEASED'
,我想解析request.gameAction = 'PREORDER'
否则,如果为response.game.gameStatus == 'RELEASED'
,我想解析request.gameAction = 'DOWNLOAD'
如果您需要更多信息,请告诉我。我相信使用set
可以在这里使用某些javascript函数吗?
答案 0 :(得分:0)
对我来说听起来很简单
* def payload = {}
* def lookup = { UNRELEASED: 'PREORDER', RELEASED: 'DOWNLOAD' }
* payload.gameAction = lookup[response.game.gameStatus]
# ...
* request payload