Forum Discussion

Jerry's avatar
17 years ago

Adding service steps with groovy

I know that with groovy you can add any of the steps that come built in as is shown in the tutorial. But, let's say that I'm testing the amazon service and I want to add the CartAdd step to my testcase.

How do I add request steps to the test case? I tried to do something
crazy. See below for what I did.

// add a properties step

def step = (com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep)(testRunner.getTestCase().getTestSuite().getTestCaseByName( "haha").getTestStepByName( "CartClear" ) )

((com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep)testRunner.testCase).importTestStep( (step), "CartAdd", 1  );

1 Reply

  • omatzura's avatar
    Super Contributor
    Hi Jerry,

    try the following for adding an existing "CartAdd" request named "Request 1" to the current testcase as a TestRequest with a SoapResponse assertion..

    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.SoapResponseAssertion

    // get request
    def iface = testRunner.testCase.testSuite.project.getInterfaceByName( "AWSECommerceServicePortType" )
    def request = iface.getOperationByName( "CartAdd" ).getRequestByName( "Request 1" )

    // create config and add teststep
    def config = WsdlTestRequestStepFactory.createConfig( request, "CartAdd RequestStep" )
    def testStep = testRunner.testCase.insertTestStep( config, -1 )

    // add a soapresponse assertion
    testStep.testRequest.addAssertion( SoapResponseAssertion.ID )

    You need to be sure that the name specified in the createConfig call is unique for the testcase, otherwise a prompt will be displayed for a new name..

    Hope this helps!