Getting the status of the previous teststep in a SoapUI Groovy step - groovy

I have the following TestCase Set up:
Datasource
Soap Request
Groovy Script
Datasource loop
I would like to get the status of the SoapRequest test step using Groovy Script test step.
It can be done as show below:
myTestStepResult = testRunner.runTestStepByName("Soap Request")
myStatus = myTestStepResult.getStatus()
But I don't want to run the TestStep by script, but just using the soapui testrunner.
In a datasink test step I can use this:
${=testRunner.results[testRunner.results.size()-1].status}
Unfortunately the above doesn't work in a GroovyScript TestStep
Any ideas?

It is possible to run the test step without using test step name and get the status as needed. And it is assumed that the there is no change in the test step sequence i.e., Soap Request step is always the previous step of Groovy Script step, and no other step comes in between the two.
Groovy Script:
log.info testRunner.runTestStep(context.testCase.testStepList[context.currentStepIndex - 1]).status

To avoid having to run the test step (again), please try the following:
results = testRunner.getResults()
status = results.get(results.size() - 1).getStatus()
log.info status
After running the test case, the script log should display the status of the previous test step.
Please note that the Groovy Script test step containing the code has to be executed when running the test case. If you run just the test step, you will get the following error:
(java.lang.ArrayIndexOutOfBoundsException)
which is normal, because you cannot get results.size() if the list is empty.

Related

SOAPUI my script step is getting overwritten after every execution of my test case

My Groovy script in SOAPUI is positioned between a Property step and a Property Transfer step. The property in both of these steps is the same and referenced in the Groovy script step. When I run the testcase, all 7 steps, the script is overwritten with the return message of the last called REST end point.
Steps include:
Rest call
property Transfer
property
groovy script
property transfer
Rest call
property transfer
Can this be a bug or is it a feature?

SOAPUI: running load tests using groovy

Using soapUI free version(5.4.0). I have simple project with test-case which has test-steps and load-tests like:
TestCase
Test-steps
one
two
LoadTests
LoadOne
LoadTwo
I want to run LoadOne and LoadTwo load tests, using Groovy scripting, in separate script. How to do that?
Assuming you're executing a Groovy test step from the same project, the following script will execute a load test called LoadOne:
import com.eviware.soapui.impl.wsdl.loadtest.*;
// Get the load test
def loadTest = testRunner.testCase.getLoadTestByName("LoadOne");
// Run the load test
WsdlLoadTestRunner loadTestRunner = new WsdlLoadTestRunner(loadTest);
loadTestRunner.start(true);
loadTestRunner.waitUntilFinished();
Then, of course, do the same for your other load test.

How can we see log.info "Message" which is added in Script Assertion in groovy for Soapui under Script Log?

If we write a
log.info "Running Test Case"
This will come under Log Output when you run as a test Step
When you run at test case level, it will go under Script Log
But when you run the same statement from script assertion, it will be shown there, but not under script log
So i would like to see the logging done from Script Assertion to appear under Script Log
I have attached the way by which we can print the log.info under Ready API Log.
It should be going to the ReadyAPI log when you actually run the test case.
When you run your script in the Script Assertion Editor, the "log" variable is a Logger that appends to that window. When your assertion runs normally as part of a test case, log will be a logger that writes to the Script Log.
If you really want to write to the Script log while testing your assertion in the Script Assertion editor, you can use:
import org.apache.log4j.Logger
Logger scriptLog = Logger.getLogger("groovy.log")
scriptLog.info "Hello World"
Or of course, just reassign the existing log variable:
import org.apache.log4j.Logger
log = Logger.getLogger("groovy.log")
log.info "Hello World"
Disclaimer: I found the name of the logger ("groovy.log") by running log.info log.name and running the test case. I did this on the Open Source version of SoapUI. It's possible that the logger name is different in ReadyAPI.

Transfer parameters between Groovy scripts in SoapUI

I have a Groovy script, it is present as a test step. I need to pass a parameter value, a variable from it to another Groovy script, which is in a script assertion, in a SOAP request. These are executed after each other. Property Transfer step is unable to do this.
You can use this statement in Script Assertion of Request
context.testCase.setPropertyValue("Prop","testing")
So here you are setting a testcase Property.
Now you can use that property in Groovy Script
def val=context.expand('${#TestCase#Prop}')
log.info val
So the value stored in Property Prop in Script Assertion is used in Groovy Script

SoapUI script assertion gotoStepByName

Background: I am using SoapUI 5.0.0 (not pro) and I have a testStep SCRIPT ASSERTION that I use to check the response that the testStep receives.
If a certain condition is met, i wish to start another testStep (can run once the script is over).
My problem is: testRunner does not work in script assertion so I cannot use testRunner.gotoStepByName("step5")
My question: is there a different option I can call that does work in a script assertion that will make the test jump to that certain testStep ?
In script assetion you've available context variable, this variable is an instance of com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext.
Through this class you can get com.eviware.soapui.model.testsuite.TestCaseRunner using getTestRunner() method and from here use gotoStepByName(String name).
You can use the follow code in your assertion script when your conditions are met:
context.getTestRunner().gotoStepByName('step5')
Note that running the script assertion "alone" the context.getTestRunner() returns null because you're running it in assertion context, the same applies if you run it from the TestStep. To get the runner property correctly you've to run the TestStep which contains the script assertion from the TestCase.
Hope this helps,

Resources