如何使用空手道框架用def值替换键 [英] How to replace a key with def value using karate framework

查看:50
本文介绍了如何使用空手道框架用def值替换键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的JSON文件:

I have a JSON file as given below:

{
    "lastname": {
        "displayName": "lastname"
    },
    "#(dynamicKey)": {
        "displayName": "#(dynamicKey)"
    }
}

当我尝试读取文件时,键和值未得到更新,但是当我使用如下所示的JSON时,值被def值替换.如果我提供动态密钥,则密钥和值都不会更新. :-(

When I try to read the file, the key and values are not getting updated but when I use JSON like below, value got replaced by the def values. If I give dynamic key both key and value are not getting updated. :-(

{
    "lastname": {
        "displayName": "lastname"
     },
     "someKey": {
        "displayName": "#(dynamicKey)"
     }
}

能否请您帮我替换动态键和值?

Could you please help me on how to replace dynamic key and value?

推荐答案

这是处理动态键的方法. #(dynamicKey)嵌入式表达式方法不起作用.

This is how you can handle dynamic keys. The #(dynamicKey) embedded-expression approach will not work.

* def dynamicKey = 'bar'
* def test = { someKey: 'foo' }
* test[dynamicKey] = 'baz'
* match test == { someKey: 'foo', bar: 'baz' }

这篇关于如何使用空手道框架用def值替换键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆