admin管理员组文章数量:1297062
I need to modify the code below so the check() will pass, even if values are not exact as long as abs(val1 -val2) < 1.00
.check(
jsonPath("$.data.attributes.contentValue")
.is(session -> session.getString("contentValue"))
)
I've tried using the session variable in multiple ways but it seems unavailable inside the validate() method. Also even the replaceAll() method is unavailable there. The code below fails to compile with Cannot resolve method 'replaceAll(String, String)'
and Cannot resolve method 'get(String)'
.check(
jsonPath("$.data.attributes.contentValue")
.transform(String::valueOf)
.validate((actualValue, session) -> {
double actualDouble = Double.parseDouble(actualValue.replaceAll("$", "").replace(",", ""));
double expectedDouble = (double) session.get("expectedDoubleValue");
return Math.abs(expectedDouble - actualDouble) <= 1.00;
}
)
)
I need to modify the code below so the check() will pass, even if values are not exact as long as abs(val1 -val2) < 1.00
.check(
jsonPath("$.data.attributes.contentValue")
.is(session -> session.getString("contentValue"))
)
I've tried using the session variable in multiple ways but it seems unavailable inside the validate() method. Also even the replaceAll() method is unavailable there. The code below fails to compile with Cannot resolve method 'replaceAll(String, String)'
and Cannot resolve method 'get(String)'
.check(
jsonPath("$.data.attributes.contentValue")
.transform(String::valueOf)
.validate((actualValue, session) -> {
double actualDouble = Double.parseDouble(actualValue.replaceAll("$", "").replace(",", ""));
double expectedDouble = (double) session.get("expectedDoubleValue");
return Math.abs(expectedDouble - actualDouble) <= 1.00;
}
)
)
Share
edited Feb 12 at 10:08
Stéphane LANDELLE
6,6232 gold badges12 silver badges16 bronze badges
asked Feb 11 at 16:36
DTMDTM
112 bronze badges
1 Answer
Reset to default 0This is really a straightforward application of the documentation: https://docs.gatling.io/reference/script/core/checks/#validate
jsonPath("$.data.attributes.contentValue")
.ofDouble()
.validate(
"is +/- 1.0",
(contentValue, session) -> {
double expectedDoubleValue = session.getDouble("expectedDoubleValue");
if (Math.abs(contentValue - expectedDoubleValue) > 0.1) {
throw new RuntimeException("Wrong value");
}
return contentValue;
}
)
本文标签:
版权声明:本文标题:verification - Is there a way to have a gatling check pass if values do not differ by more than 1.00? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647181a2390254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论