我想断言价格总额大于price_net。您能告诉我如何正确实现吗?这就是我所做的atm。
Scenario: Testing
* def response =
"""
{
"prices": [
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" }
]
}
"""
* match each response.prices[*].price_gross == '#? _ >= 0 && _ >= response.prices[*].price_net'
我认为断言语句中的'*'是问题。因为当我运行
* match response.prices[0].price_gross == '#? _ >= 0 && _ >= response.prices[0].price_net'
它工作正常。请提出建议。提前致谢。
答案 0 :(得分:2)
示例代码:
Feature: Validation
Scenario: Validation
* def diff =
"""
function (A, B) {
var C = [];
for(var i = 0; i < A.length; i++) {
C.push(parseFloat(A[i]) - parseFloat(B[i]));
}
return C;
}
"""
* def response =
"""
{
"prices": [
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" }
]
}
"""
* json temp = response
* def pgarr = get temp.prices[*].price_gross
* def pnarr = get temp.prices[*].price_net
* def sub = diff(pgarr,pnarr)
* match each sub == '#? _ >= 0'