3
votes

I have 5 test steps in a test case and i want to write a script assertion for a test step

Like

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def httpResponseHeaders = context.testCase.testSteps["Step1"].testRequest.response.responseHeaders
    def httpStatus = httpResponseHeaders["#status#"]
    def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
    if (httpscode == "500")

I want to re-run the test step named as step 1

I know that testRunner class is not present in Script assertion is there a way to do it with messageExchange variable class

I saw an answer on stack overflow

`messageExchange.modelItem.testStep.testCase.getTestStepByName("Step1").run(context.getTestRunner(),context)`

I tried the code but as soon as i click run SOAP UI hangs and I have to force close the SOAP UI application

3
I believe, you may want to have a groovy script rather than putting the code to run the step in assertion step. - Rao
I completely understand his need. I needed to create some basic groovy needed to be run by the script assertion and then call it from many asssertion scripts with only some parameter or none, to avoid repeating the same code in many assertions and have a mess there. - Martin Vondráček

3 Answers

1
votes

To run a test step from script assertion you may use this

    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner

    def Runner = new WsdlTestCaseRunner(messageExchange.modelItem.testStep.testCase, new StringToObjectMap())

yourTestStep= messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["ScriptLibrary"].testCases["Library"].testSteps["Lib"]


    yourTestStep.run(Runner,context)
1
votes

Your code is fine, except your logic is flawed, because you encounter the error 500 for the first time and then you call the same step again and it fails again with 500 and so on. You would need to get different status, before your Java runs out of memory.

So if you want to do something like that, you have to implement some kind of counter (using TestCase, TestSuite, Project or Global property) to perform this loop only several times and then fail.

Anyway this worked for me:

def utilitiesSuite = messageExchange.modelItem.testStep.testCase
  .testSuite.project.getPropertyValue('utilitiesTestSuiteName');
messageExchange.modelItem.testStep.testCase.testSuite.project
  .testSuites[utilitiesSuite].testCases["Test Case utility name"]
  .run(null, true);

In this case we have all "utilities" = test cases with some often needed functionality in a dedicated test suite and I wanted its name to be possible to set up on Project level, of coures the Test Suite name can be put there directly as for example "Utilities'. Also i have tried with this:

context.getTestRunner()

As the first parameter in the methor run instead of the null, but it worked only when testing the one requirement, not when running whole test case or test suite.

0
votes

I let here another example that worked for me. It's an assertion script, which runs a testStep basing on a response node value.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context );
def holder = groovyUtils.getXmlHolder( "yourTestStep#response" );
def myValue = holder.getNodeValue( "//theNameSpace:yourNode" );

if(myValue == 'whateverYouWant'){
    //com.eviware.soapui.support.UISupport.showInfoMessage(myValue);
    def Runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(
    messageExchange.modelItem.testStep.testCase, new com.eviware.soapui.support.types.StringToObjectMap());

    def mySteps= messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["yourTestSuite"].testCases["yourTestCase"].testSteps["yourTestStep"];
    mySteps.run(Runner,context);
}