定义可重用方法库的 SoapUI



我现在在我的 SoapUI 项目中遇到了复制粘贴大量代码的情况,并认为我会有某种可以执行我大部分任务的辅助函数库。

所以我有一个测试套件,代码本身在这个测试套件的 Groovy 脚本测试步骤中。这个想法是,我使我的帮助程序方法可用于我所在的上下文(REST 测试请求步骤)。

它实例化得很好,但问题是当我想调用run(testRunner, context)时,我无法访问testRunner属性。我读过一些关于它的东西,就是这样。

有人知道解决这个问题的方法吗?

我使用与您相同的脚本库方法。我使用了Kerry Doan在 http://www.doan.me/script-library-in-soapui-free.aspx 中描述的方法

当我尝试从项目加载脚本访问此脚本库时,我无法访问testRunner,因此我创建了testRunner对象,并且由于我无法访问上下文对象,因此我也必须创建它。

查看下面的代码。

import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
//to create the testRunner object I need a testCase object and a new StringToObjectMap
//I initially used the test case in the script library but as i needed the 
//testRunner object to the test case being executed so i created the object to
//the test case being executed.
//I did not want to worry about test suite or test case names so i used their index 
//assuming that there will be at least one test suite and at least one test case when
//this script is run
testCase = project.getTestSuiteAt(0).getTestCaseAt(0)
tcRunner = new WsdlTestCaseRunner( testCase, new StringToObjectMap() );
//A context is essentially a WsdlTestRunContext object and as you can see below all i 
//have done to create that is pass it a test step object which was obtained by using index
//rather than name.
tStep = testCase.getTestStepAt(0)
tcContext = new WsdlTestRunContext(tStep)
//my script library is in a seperate project called `Script Library` and all the 
//groovy scripts are in a test suite called `Script Library`
scripts = project.workspace.projects["Script Library"].testSuites["Script Library"];
scripts.testCases["Scripts"].testSteps["runTest"].run(tcRunner, tcContext);

相关内容

  • 没有找到相关文章

最新更新