[英]In Karate DSL, how can I use the replace text for other data types such as int, float, Big, etc.?
I found the below example on github. 我在github上找到了以下示例。
def text = 'hello world bye' def text ='你好世界再见'
replace text | 替换文字| token |
令牌| value |
价值| |
| one |
一| 'cruel' |
“残酷” | |
| two |
二| 'good' |
'好'|
match text == 'hello cruel world good bye' 匹配文字=='你好残酷的世界再见'
What If the value I want to replace can only accept integers or other data types? 如果我要替换的值只能接受整数或其他数据类型怎么办? For example,
例如,
I was not able to put the token inside another file because the json validator does not like the <> without the double quotes. 我无法将令牌放入另一个文件中,因为json验证程序不喜欢<>没有双引号的情况。 any suggestions?
有什么建议么?
Replace is meant for text not JSON, read the doc carefully please. 替换用于文本而非JSON,请仔细阅读文档。 First, there is no problem with numbers and replace:
首先,数字和替换没有问题:
* def text = 'hello <name> how many <hours>'
* replace text
| token | value |
| name | 'John' |
| hours | 200 |
* match text == 'hello John how many 200'
Now, if you are trying to fiddle with JSON, just use the set
keyword. 现在,如果您尝试摆弄JSON,只需使用
set
关键字。
* def json = { hello: '', hours: null }
* set json
| path | value |
| hello | 'John' |
| hours | 200 |
* match json == { hello: 'John', hours: 200 }
Note that the above would work even if you omit the first line. 请注意,即使您省略第一行,上述内容也可以使用。 Also refer to embedded expressions as another way to substitute values in JSON, refer to the doc.
另请参阅嵌入式表达式,作为在JSON中替换值的另一种方法,请参考文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.