如何简化 CustomKeywords 调用?

How to simplify CustomKeywords calls?

有一种方法可以简化 CustomKeywords 对测试用例的调用吗?

的确,每次都使用CustomKeywords.'package.class.method'(param1, param2)并不理想。

所以我正在寻找一种方法来做类似的事情:

line 1 : CustomKeywords.package.class as EasyCall
line W : ...
line X : def result = EasyCall.method(param1, param2)
line Y : ...
line Z : def result2 = EasyCall.method(param1, param2)

而不是

line W : ...
line X : def result = CustomKeywords.'package.class.method'(param1, param2)
line Y : ...
line Z : def result2 = CustomKeywords.'package.class.method'(param1, param2)

有人知道吗?

Katalon 中的

"Custom Keyword" 只是一种普通的旧方法。因此,您在 Groovy 或 Java 中所做的一切也适用于此。

因此,为了简化方法调用,您需要导入

import package.class as EasyCall

并且您在 package 中的方法需要是 static:

package package

@Keyword
def static method1(param1, param2){
    // body of method1
}

然后您只需在测试脚本中调用该方法:

EasyCall.method1(param1, param2)