SoapUI定义了可重用方法的库 [英] SoapUI defining a library of reusable methods
问题描述
所以我有一个测试套件,代码本身在这个测试套件的Groovy Script测试步骤中。这个想法是我使我的帮助器方法可用于我所处的上下文(一个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
//创建testRunner对象我需要一个testCase对象和一个新的StringToObjectMap
// I最初在脚本库中使用了测试用例,但由于我需要
// testRunner对象来执行测试用例,所以我创建了对象到
//执行测试用例。
//我不想担心测试套件或测试用例名称,所以我使用它们的索引
//假设至少有一个测试套件和至少一个测试用例,当
//这个脚本运行
testCase = project.getTestSuiteAt(0).getTestCaseAt(0)
tcRunner = new WsdlTestCaseRunner(testCase,new StringToObjectMap());
//上下文本质上是一个WsdlTestRunContext对象,正如你在下面可以看到的所有i
//已经完成创建,它传递一个测试步骤对象,该对象通过使用索引
//而不是名字。
tStep = testCase.getTestStepAt(0)
tcContext = new WsdlTestRunContext(tStep)
//我的脚本库位于一个名为`Script Library`的独立项目中,所有
// groovy脚本位于名为`Script Library`的测试套件中
scripts = project.workspace.projects [Script Library]。testSuites [Script Library];
scripts.testCases [Scripts]。testSteps [runTest]。run(tcRunner,tcContext);
I'm running into copy-pasting a lot of code at the moment in my SoapUI projects, and thought I'd have some sort of library of helper functions that can carry out most of my tasks.
So I have a test suite for this, and the code itself is in a Groovy Script test step in this test suite. The idea is that I make my helper methods available to the context I'm in (a REST test request step).
It instantiates fine and all that, but the problem is that when I want to invoke run(testRunner, context)
, I am not having access to the testRunner
property. I've read something about that this is how it is.
Anyone know a way around this?
I am using the same method as you for script library. I used the method described by Kerry Doan at http://www.doan.me/script-library-in-soapui-free.aspx
When i tried to access this script library from project load script i did not have access to the testRunner so i created the testRunner object and as i did not have access to the context object i had to create that too.
Check out the code below.
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);
这篇关于SoapUI定义了可重用方法的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!