I created a testSuit, and I have some test steps. The objective is to run the test steps one by one, and set the status to OK or to FAILED, for that I get the httpStatus code and set it to FAILED or OK.
This part seems to be good. The problem is, with the code I have, in the groovy script when I click the green button to run the script it gives me the message: "java.lang.NullPointerException: Cannot invoke method setStatus() on null object error at line 17". and the color of the script keeps red.
BUT, if I click on "Test Steps", a small window will appear with the test steps, the groovy script, etc...If I right click the groovy script and choose "Test from here" The script run, the test step I run in the script turn green or red depending if it fails or pass, and the groovy script turns blue.
So... I don't understand whats happening... what's the diference of opening the "Groovy Script" window and run it from there, and opening the "Test Steps" window and running the script from there?
The code:
import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
def example = testRunner.runTestStepByName("example");
def myStep = context.testCase.getTestStepByName("example")
def exampleResult = testRunner.results.find { it.testStep.is(myStep) }
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def httpResponseHeaders = context.testCase.testSteps["example"].testRequest.response.responseHeaders
def httpStatus = httpResponseHeaders["#status#"]
def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
log.info("HTTP status code: " + httpStatusCode)
if (httpStatusCode != "200"){
testRunner.fail("failed");
exampleResult.setStatus(TestStepStatus.FAILED);
} else {
log.info("passed");
exampleResult.setStatus(TestStepStatus.OK);
}
Note: Im colorblind, so not sure 100% if the green I said above is really green or yellow and the blue could be pink...
Thanks for the help!
Found the solution.
There is no need of some things in my code.
The exampleResult
, and myStep
are not needed.
I can just use the example.setStatus(TestStepStatus.OK)
.
Worked as expected after that.