Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Karate properties.json在读取*.feature文件中的属性时引发ReferenceError_Json_Properties_Karate - Fatal编程技术网

Karate properties.json在读取*.feature文件中的属性时引发ReferenceError

Karate properties.json在读取*.feature文件中的属性时引发ReferenceError,json,properties,karate,Json,Properties,Karate,最近我将空手道从0.6.2更新到了0.9.5,在我的整个测试用例中使用了许多ReferenceError的w.r.t-properties.json 我已完成以下设置: test-properties.json 测试验证功能 然后在我的第一个场景中使用道具: And header User-Agent = props.headers.Accept-Language And header X-Forwarded-For = props.headers.x-forwarded-for 但是,运行此

最近我将空手道从0.6.2更新到了0.9.5,在我的整个测试用例中使用了许多ReferenceError的w.r.t-properties.json

我已完成以下设置:

test-properties.json 测试验证功能 然后在我的第一个场景中使用
道具

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
com.intuit.karate.exception.karate exception:test auth.feature:14-javascript评估失败:props.headers.Accept-Language,ReferenceError:第1行中未定义“语言”

我尝试将属性文件添加到与测试身份验证功能相同的包中,但没有成功。问题似乎在于读取json文件。我知道空手道0.6.2可以评估文件类型,并在内部以其本机格式对其进行解析。还是这样吗?如果没有,那么从Karate0.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

因此,如果您仍然被卡住,请遵循以下过程:

在读取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

因此,如果您仍然被卡住,请遵循以下流程:

感谢您的快速响应。尝试此解决方案时,我仍然收到一个javascript评估失败错误:
javascript评估失败:props.headers。['x-forwarded-for'],:1:14预期标识,但找到[props.headers.'x-forwarded-for']^在第14列的第1行,干杯,在功能中注入JSON是有效的。如果我的JSON稍微变大,我可能会在将来提出一张罚单,因为将*.properties.JSON放在它自己的文件中并以这种方式注入会更干净。非常感谢。@Magu如果注入或读取f,应该没有什么区别ROM是一个文件。这就是为什么我会敦促你考虑提交一个工作示例,因为如果有一个bug,我想修复它,感谢快速响应。在尝试这个解决方案时,我仍然得到一个JavaScript评估失败的错误:<代码> JavaScript评估失败:道具。,:1:14预期标识,但找到[props.headers.[x-forwarded-for']^在第14列的第1行,干杯,在功能中注入JSON是有效的。如果我的JSON稍微变大,我可能会在将来提出一张罚单,因为将*.properties.JSON放在它自己的文件中并以这种方式注入会更干净。非常感谢。@Magu如果注入或读取f,应该没有什么区别ROM文件。这就是为什么我会敦促您考虑提交一个工作示例,因为如果有bug,我想修复它。