json - 在读取 *.feature 文件中的属性时,Karate properties.json 会引发 ReferenceError
问题描述
最近将空手道从 0.6.2 更新到 0.9.5,我在整个测试用例中使用的 properties.json 中有许多 ReferenceError。
我有以下设置:
测试属性.json
{
"headers": {
"x-client-ip": "192.168.3.1",
"x-forwarded-for": "192.168.3.1"
}
}
test-auth.feature
Background:
* def props = read('properties/test-properties.json')
然后props
我在第一个场景中进一步使用:
And header User-Agent = props.headers.Accept-Language
And header X-Forwarded-For = props.headers.x-forwarded-for
但是,在运行此程序时,我遇到以下问题:
com.intuit.karate.exception.KarateException: test-auth.feature:14 - javascript evaluation failed: props.headers.Accept-Language, ReferenceError: "Language" is not defined in <eval> at line number 1
我尝试将属性文件添加到与 相同的包中test-auth.feature
,但无济于事。问题似乎与读取 json 文件有关。我知道空手道 0.6.2 可以评估文件类型并在内部以其本机格式对其进行解析。现在还是这样吗?如果没有,从空手道 0.9.5 中的 properties.json 读取的解决方案是什么。
解决方案
读取 JSON 文件时应该没有任何改变。空手道将 RHS 评估为 JS,所以我认为这是解决方案:
And header User-Agent = props.headers['Accept-Language']
And header X-Forwarded-For = props.headers['x-forwarded-for']
编辑:这对我有用:
* def props = { headers: { 'Accept-Language': 'foo', 'x-forwarded-for': 'bar' } }
* url 'http://httpbin.org/headers'
* header User-Agent = props.headers['Accept-Language']
* header X-Forwarded-For = props.headers['x-forwarded-for']
* method get
导致:
1 > GET http://httpbin.org/headers
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: httpbin.org
1 > User-Agent: foo
1 > X-Forwarded-For: bar
因此,如果您仍然卡住,请按照以下流程操作:https ://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
推荐阅读
- arrays - Numpy 抱怨数组模棱两可:ValueError: The truth value
- r - 使用R查找向量中数字的频率
- reactjs - 反应渲染 { [key: string]: object }
- javascript - 日期编辑:从月份中删除零前缀
- javascript - 如何以角度从数组中的数组中删除未定义/空值
- selenium-webdriver - 使用 autoIt 和 selenium 拖放本地文件
- c# - C# LINQ 排列多列值并重新分配到特定列
- c# - 左连接具有某些参数的两个数据表
- r - 汇总 data.table 中名称具有特定模式的列
- qb64 - “火”在击中右边缘后返回 (X 0)