我在功能文件的背景中有一个声明,
def token = Java.type("Calling a static method from a java class")
我的功能文件中有 4 个场景,这个 java 类被调用了 4 次。如何只调用这个java类一次?
最佳答案
根据 Karate 文档,您必须使用callonce
Variables set using def in the Background will be re-set before every Scenario. If you are looking for a way to do something only once per Feature, take a look at callonce. On the other hand, if you are expecting a variable in the Background to be modified by one Scenario so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into one scenario. Keep in mind that you should be able to comment-out a Scenario or skip some via tags without impacting any others. Note that the parallel runner will run Scenario-s in parallel, which means they can run in any order.
请检查
关于java - 如何在功能文件中仅在后台运行一次 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56701871/