问题描述
我想使用空手道,是否可以设置If条件,而无需调用其他功能文件(并且不使用JavaScript)->在以下情况下使用空手道功能文件代码块:
Using Karate, I would like to know, if it is possible to set If condition without necessity of calling different feature file (and not using JavaScript) -> using block of Karate feature file code in condition:
例如应该有可能做类似的事情?
e.g. it should be possible to do something like that?
* if (variable==1) {
* delay(3000)
* retry().click('{button[3]/span}Text1')
}
{
* retry().click('{button[2]/span}Text2')
* delay(3000)
}
是否可以在不使用仅包含几行代码的单独功能文件的情况下以某种方式进行此操作?你有什么建议吗?
Is it possible to do somehow like this without using separate feature file with only few rows of code? Do you have any advice?
推荐答案
是的,使用 eval
关键字-您可以纯"JS和多行代码:
Yes, use the eval
keyword - and you can do "pure" JS and on multiple lines:
* eval
"""
if (variable == 1) {
delay(3000);
retry().click('{button[3]/span}Text1');
} else {
retry().click('{button[2]/span}Text2');
delay(3000);
}
"""
顺便说一句,由于您似乎在进行大量高级测试,所以我建议您开始使用1.0 RC版本,以免感到意外,并且还可以提供反馈:"> https://github.com/intuit/karate/wiki/1.0-upgrade-guide
By the way, since you seem to be doing a lot of advanced testing, I suggest you start using the 1.0 RC version so that you don't get any surprises and you can provide feedback also: https://github.com/intuit/karate/wiki/1.0-upgrade-guide
这篇关于在不使用其他功能文件调用的情况下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!