SoapUI defining a library of reusable methods

别等时光非礼了梦想. 提交于 2019-12-12 22:09:03

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/22760902/soapui-defining-a-library-of-reusable-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!