getting name of previous test step in SoapUI groovy script - groovy

I'm new to groovy scripting in SoapUI and a bit confused regarding the amount of information available, so I may just have overlooked the answer to this.
There is a method context.getCurrentStep() available in scripts which loaded the GroovyUtils. But in a script step this, of course, returns the name of the script step itself.
Now I want to access the name (more precisely the response) of the previous step without using it's name explicitly. Is there an easy method to acchieve this?

You could do something like:
def currentStepInd = context.currentStepIndex
def previousStep = testRunner.testCase.getTestStepAt(currentStepInd - 1)
log.info previousStep.name
More information is available in the API JavaDocs.

You would want to do the following in your script:
def response = context.expand( '${previous_step_name#Response#}' )

Related

Pass runtime arguments in Gatling

I am trying to pass runtime args while running gatling tests for couple of fields. For example I am trying to pass number of users dynamically when running the test. How can I do that?
This is documented in the official documentation:
This can be done very easily with additional JAVA_OPTS in the launch script:
JAVA_OPTS="-Dusers=500 -Dramp=3600"
val nbUsers = Integer.getInteger("users", 1)
val myRamp = java.lang.Long.getLong("ramp", 0L)
setUp(scn.inject(rampUsers(nbUsers).during(myRamp.seconds)))
// Of course, passing a String is just as easy as:
JAVA_OPTS="-Dfoo=bar"
val foo = System.getProperty("foo")
The easiest way is going for Java system properties, for example if you have workload model defined as:
setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
if you change it from hard-coded to dynamic reading of the system property like:
setUp(scn.inject(atOnceUsers(Integer.parseInt(System.getProperty("userCount")))).protocols(httpProtocol))
you will be able to pass the desired number of users dynamically via -D command-line argument like:
gatling.bat -DuserCount=5 -s computerdatabase.BasicSimulation
More information: Gatling Installation, Verification and Configuration - the Ultimate Guide

SoapUI: Transfer groovy script results using Property Transfer

I am an absolute noob in SoapUI. I am looking out for answer on this but somehow could not really find it.
I am in a situation where I would like to transfer two of the groovy scripts's results to another Groovyscript. Unfortunately, while using Property Transfer, the destined groovy script gets fully overriden by the return value by the source script. How shall I approach this?
Please find below the example for the same:
As you may see, I would like to pass the value of the transferred result of generateCreated and generateNonce to the generatePassword script in testRunner.testCase.getPropertyValue("Nonce") and testRunner.testCase.getPropertyValue("Created")
But this just doesnt seem to work for me.
You don't need a Property Transfer teststep for that.
You just let your first two scripts run - as you already are doing.
Then in your third Groovy Script, you just pull the results into variables.
This can be done using something like
def result = context.expand( '${Groovy Script#result}' )
In your case above, I suspect you would adjust that to something like
def created = context.expand( '${generateCreated#result}' )
def nonce = context.expand( '${generateNonce#result}' )
Insert those lines in your script whereever you need those variables, and then you have the variables "created" and "nonce" holding the results.

Call test suite property within the request in SoapUi

all
I am using free version of SoapUI.
What I have is a test suite with many test cases. In each test case there is a request where I need to specify a date. So I want to create a general script for all cases and just call the result of it in each request I need.
What I do:
1. I have test suite SaveOperation where in SetupScript window at the bottom I write script:
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def windowClosed = sdf.format(new Date()-20)
log.info(windowClosed)
2. In this test suite I have many test cases as I wrote. So when for example in test case named SaveValid I need to specify Date parameter I write the following right in the xml request (in date parameter):
${#SaveOperation#windowClosed}
But it doesn't work. Could anyone suggest what is wrong with this way?
thank you in advance
You have the correct approach. log.info() will only write the information to a log.
change
log.info(windowClosed)
to
testSuite.setPropertyValue("windowClosed", windowClosed.toString())
and then refer to it as:
${#TestSuite#windowClosed}

Getting values of properties in SoapUI's groovy

I'm pretty new to testing and SoapUI and I've just faced a problem:
I have 2 soap requests from which I transfer data (using PropertyTransfer) to Properties - I can do that and it works fine for me.
But now I would like to take those values in my groovy script (which is next step of my testcase). How to do that? So far, I have found following:
testRunner.testCase.getPropertyValue("SomeProp")
But it doesn't work for me. I guess it's not that Properties. Any tips?
In the Groovy script panel you can right-click and select Get Data, to help you out. You will end up with something like this:
context.expand( '${Properties step#SomeProp}' )
Same thing can also be written as:
testRunner.testCase.testSteps['Properties step'].getPropertyValue("SomeProp")
Few cents:
if we are loading properties file through external file via -Dsoapui.properties=\tmp.properties
Contents of tmp.properties
serialNumber=908664374
ideal way to load the property 'serialNumber' in groovy file would be,
def serialnumber = context.expand('${#serialNumber}')
But if you have a property at any level [test suites, test cases or project] inside your SOAPUI project, say you have it at project level, then it would be
def serialnumber1 = context.expand('${#Project#serialNumber}')
The first expression works with:
context.expand( '${Properties_step#SomeProp}' )
To read property from Project level properties
testRunner.testCase.testSuite.project.getPropertyValue( "PropertyName")
To read property from Test Case level properties
testRunner.testCase.getPropertyValue("PropertyName")
Two answers are possible for this type of scenarios ,
Setting and Getting the Property values,
Message Exchange
Test Runner
Message Exchange :
def testCase=messageExchange.modelItem.testCase.getPropertyValue("Propertyname")
Test Runner:
testRunner.testCase.getPropertyValue("PropertyName")
Note : context also helps to retrieve the same .

getXmlHolder and context.expand - What does the arguments description mean

I am trying to insert values into the Request and Capture the response from the soapui pro Testsuite/testcase/testStep, using groovy script, without creating any property or assertions using soapui pro wizard. Everything i am trying to do using groovy script file in Soapui pro. But after 11 days of my self learning process I am forced to ask the in the forum:
I went thru almost 100 sites talking about how to capture request/response value.
But none explains the following:
getXmlHolder ("DeliverStatus#Request")
what does "deliveryStatus" & "Request" means and what does it contains. Which part of xml file is it. What does it signify
context.expand
For all my attempts i have got Null exception.
But i have been able to successfull script using groovy in the "Script tab in the Response section". But unable to do in using testsuite Groovy Script.
Please help.. Thanking all in advance
Regards
Am
DeliverStatus is basically meaningless - it is the name of your test step.
Request means that you look at the XML request that will be sent by SoapUI.
You can replace Request with Response and get the result of the API call.
context.expend allows you to get the value of the request or the response as well as specific XPaths within them. I'm not familiar with the getXmlHolder method - but it looks like it gets an XML string as input (can be a fragment) and turns it into an object you can work with.
My recommendation - if you are not using it already, is to right click on the Groovy editing area and choose Get Data --> Test Suite --> Test Case --> Test Step --> Response --> and navigate to the path in the response to which you want to access.
This will set the value of that XML fragment into a string variable of your choosing.
Afterwards you can use the getXmlHolder to convert that string into an object.
I also recommend using the XmlSlurper for parsing an XML string into an object.

Resources