我想在一个groovy脚本中定义一个类,我可以通过SoapUI中的其他groovy脚本重用它.
我想尝试在TestSuite属性中定义我的类,但它不起作用.我想避免在JAR中定义类,因为我们在团队中工作,每个人都必须在他们的SoapUI中导入JAR才能运行我的测试.我使用SoapUI 3.6.1
以下是我的TestSuite的制作方法:
TestSuite
TestCase
TestSteps
Init (Groovy Script)
GetResponse1 (Test Request)
Test1 (Groovy Script)
GetResponse2 (Test Request)
Test2 (Groovy Script)
Run Code Online (Sandbox Code Playgroud)
为了简化测试,我在'Test1'中定义了一个类,我想在'Test2'中重用这个类.理想情况下,我会在'Init'中定义该类,并且任何其他groovy脚本都可以访问它.
我怎样才能实现这一目标?
基于 @Abhey Rathore的链接,这里是如何在SoapUI的groovy脚本中定义一个全局类:
MyRepositorylibMyClassclass在调用的groovy脚本中class,复制并粘贴下面的代码:
class MyClass {
// The three following fields are MANDATORY
def log
def context
def testRunner
// The constructor below is MANDATORY
def MyClass(logIn, contextIn, testRunnerIn) {
this.log = logIn
this.context = contextIn
this.testRunner = testRunnerIn
}
def myMethod() {
this.log.info 'Hello World!'
}
}
// Other scripts elsewhere in SoapUI will access the reused class through their context
context.setProperty( "MyClass", new MyClass(log, context, testRunner) )
Run Code Online (Sandbox Code Playgroud)
在任何项目中,您都可以使用以下代码段导入全局类:
// Import the class
def currentProject = testRunner.testCase.testSuite.project
currentProject
.testSuites["lib"]
.testCases["MyClass"]
.testSteps["class"]
.run(testRunner, context)
// Now use it
context.MyClass.myMethod()
Run Code Online (Sandbox Code Playgroud)
SoapUI 5.2.1
我非常确定您必须创建一个 JAR 文件并将其放入 \bin\ext 中。
SoapUI 将在重新启动时自动选择它(您应该在启动内容中看到它)。
基本上,您只需创建一个 Java 或 Groovy 项目,将其导出(使用 Eclipse),它就会工作。SoapUI 可能会覆盖您的依赖项,但如果没有,您也可以添加这些 JAR(比创建可运行的 JAR 更安全,因为 SoapUI 可能使用您所使用的不同版本)。
如果您需要帮助,请发布相关问题。
| 归档时间: |
|
| 查看次数: |
7181 次 |
| 最近记录: |