Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

Is it possible to use karate 'match' inside conditional statement?

Find the example here.

def a = condition ? " karate match statement " : "karate match statement"

Is it possible to do something like this??

question from:https://stackoverflow.com/questions/65951088/how-to-use-if-else-condition-in-assertion-karate-framework

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is not recommended practice for tests because tests should be deterministic.

The right thing to do is:

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

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...