是否可以在条件语句中使用空手道“匹配"? [英] Is it possible to use karate 'match' inside conditional statement?
问题描述
在此处查找示例.
def a = 条件 ?空手道比赛声明":空手道比赛声明"
有可能做这样的事情吗??
这不是测试推荐的做法,因为
karate.match()
的结果将返回格式为 { pass: '#boolean', message: '#string' }
如果上述选项都不起作用 - 这意味着您正在做的事情真的很复杂,所以 编写Java互操作/代码来处理这个
Find the example here.
def a = condition ? " karate match statement " : "karate match statement"
Is it possible to do something like this??
This is not recommended practice for tests because tests should be deterministic.
The right thing to do is:
- craft your request so that the response is 100% predictable. do not worry about code-duplication, this is sometimes necessary for tests
- ignore the dynamic data if it is not relevant to the
Scenario
- use conditional logic to set "expected value" variables instead of complicating your
match
logic - use self-validation expressions or schema-validation expressions for specific parts of the JSON
- use the
if
keyword and call a second feature file - or you can even set the name of the file to call dynamically via a variable - in some cases
karate.abort()
can be used to conditionally skip / exit early
That said, if you really insist on doing this in the same flow, Karate allows you to do a match
via JS in 0.9.6.RC4 onwards.
See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397
The result of karate.match()
will return a JSON in the form { pass: '#boolean', message: '#string' }
If none of the above options work - that means you are doing something really complicated, so write Java interop / code to handle this
这篇关于是否可以在条件语句中使用空手道“匹配"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!