How To Get Details of Any Type of Test Steps To A Groovyscript Test Step
How To Get Details of Any Type of Test Steps To A Groovyscript Test Step
By default if you are using the SOAP UI Pro , you get the following option through which you can
very easily import data from any test step. Once you create a Groovyscript test step like below ,
by right clicking on the test suite / test case of SOAP UI
Once you are in the Groovyscript editor - You can just right click(your mouse ofcourse ) and you
will the the option to Get Data as seen below
As you can see, If you are using SOAP UI pro , You can get all the properties that you stored in
each Global level, Test Suite level, Test case level can all be accessed . But the issue is that
only those elements which you store as properties can be retrieved using get data . So if I
choose one particular value - Eg. LogRequestResponse
If I choose one property from Test suite level the code will look like this
If I choose property from Test Case level the code will have to look like this
As I said , Only those property that you set manually or through script can be accessed like this .
If you want to capture some runtime value , like status of assertion . You cant use the get data .
Now here is where the following groovyscript code might be useful to you .
First step is to get all the test requests in a particular SOAP UI test case into an object .
Here I am going to store all the test step of the Test case into an object called requests
log.info requests
Now that all the test steps are available to us, We can call different methods of the object to get
whatever information that we want.
One simple and very useful effective method is the .name method or getLabel() method. In order
to do that we need to retrieve the selective type of test step . In SOAP UI there are several test
step types such as
Suppose you want to get all the SOAP Test requests into one object you can do that using the
following code .
From the previous code we know that the groovy class type for the SOAP Test request
is com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
Now we can retrieve all the SOAP test request from the Test case using the following code
def SOAPrequests =
testRunner.testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestReq
uestStep.class )
def SOAPrequests =
testRunner.testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestReq
uestStep.class )
def requestsName = SOAPrequests.name
If I do a log.info for reqeustsName , I can get all the name of the SOAP test requests like follows
This is an java class array type . So you can do a groovy loop to perform any operation for all the
elements in the array
For the array requestsName , Elements of the array can be accessed based on the numeric
index of the elements.
For eg - requestsName[1] will give the first test step which is - FindPartyContacts_Shpr
You can then get various associated information using the different methods
Firstup you need to get the Test step object for the name using the code
def testStepObj= testRunner.getTestCase().getTestStepByName("FindPartyContacts_Shpr")
So if you have around 10 different assertion in your test step - FindPartyContacts_Shpr, You can
get the status of all these assertions, If they are pass or fail using this technique. This can be
further used to either set any property or to write it to any file using data sink .
Posted 12th June 2013 by Sureshkumar