简体   繁体   中英

Run a test step in Script assertion SOAP UI

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

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)

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM