简体   繁体   English

在空手道DSL中,如何将替换文本用于其他数据类型,例如int,float,Big等?

[英]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, 例如,

  • replace text | 替换文字| token | 令牌| value| 值| | | hours | 小时 90 | 90 | | | price | 价格| 123.45 | 123.45 | | | quantity | 数量 999999999999 | 999999999999 |

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.

相关问题 如何在Scala / Play中将JSON转换为简单的旧数据(Map,List,String,Int等) - How do I turn JSON into plain old data (Map, List, String, Int etc.) in Scala/Play 如何在没有占位符的情况下更改空手道 DSL 中文本响应的所有外观? - How can you change all appearances of a text response in Karate DSL without having a placeholder? 在字符串的 Json 数组中,如何匹配存在的字符串的一部分? 空手道DSL - In Json array of strings, how can I match a part of string is present? Karate DSL 用于内置类型(float、int 等)的 json_encoders - pydantic `json_encoders` for builtin types (float, int, etc) 如何使用简单的查询将 JSON 文件导入 MySQL 数据库,而不实际将其转换为任何其他文件格式,如 CSV 等? - How can I import a JSON file into MySQL database, using a simple query, without actually converting it to any other file formats like CSV etc.? 如何在空手道中将变量用作 json 键? - How can I use a variable as a json key in karate? API 返回包含换行符等的 json。我该如何清理我的 json? - API returns json containing linebreaks etc. how can i clean my json? 如何通过 React 在资源(.json、.csv 等)上使用代码拆分 - How to use code splitting on a ressouce (.json, .csv, etc.) with React 如何在 Django JSONField 数据上聚合(最小/最大等)? - How to aggregate (min/max etc.) over Django JSONField data? 如何提高大数据性能? - How can I increase big data performance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM