首页 > 解决方案 > 在 BAT CLI for Mulesoft 的 API URL 中注入自定义值

问题描述

我在 Mulesoft 中使用 BAT CLI 编写功能 API 测试 - https://docs.mulesoft.com/api-functional-monitoring/bat-bdd-reference

我正在尝试将 URL 中 API 调用响应中获得的值用于另一个后续 API 调用。

import * from bat::BDD
import * from bat::Assertions
import * from bat::Mutable

var context = HashMap()
---
it ("capture a value from a API response") in [
    GET https://first.api.call/abc,
    execute [
            // This works
            context.set('myVal',$.response.body.myVal)
          ]
],
it ("use the value in the second API URL") in [
    // I am trying to inject the value obtained above in the URL below
    GET https://first.api.call/{context.get('myVal')}
    ....
]

显然我没有得到正确的语法。{context.get('myVal')}不起作用。我也试过了$({context.get('myVal')})$(context.get('myVal'))也不行。

谁能说出正确的语法是什么?

标签: restapiautomated-testsfunctional-testingmulesoft

解决方案


这有效: GET https://first.api.call/$(context.get('myVal'))

干杯!


推荐阅读