Search code examples
groovysoapui

Cloning SOAP UI Test Steps using Groovy Script


Recently I have started to improve my SOAP UI testing projects by using Groovy Scripts. I am just on a beginner level more often amending and reusing scripts than creating ones of my own, hope that soon I will be able to create custom scripts :)

These days I have searched for a way to clone existing Test Steps from a Test Case into another Test Case. I have searched in the net for some ways or ready scripts that I can implement in my projects, but so far I have no luck finding what I need :(

Can you help me with this by showing me some examples how this can be done?

Kind regards, Kristiyan


Solution

  • You can clone a test step (or a whole test case) from one place to another easily enough:

    def originalTestStep = testRunner.testCase.testSuite.project
            .getTestSuiteByName("OriginalTestSuite").getTestCaseByName("OriginalTestCase")
            .getTestStepByName("OriginalTestStep")
    
    testRunner.testCase.testSuite.project
            .getTestSuiteByName("TargetTestSuite").getTestCaseByName("TargetTestCase")
            .cloneStep(originalTestStep, "clonedTestStep")
    

    But, this would be creating a maintenance problem. A better option would be to put your common test steps into a test case and then run that test case from your many other test cases. There's a Run Test Case test step you can use or you can do it from Groovy:

    def testCase = testRunner.testCase.testSuite.project
            .getTestSuiteByName("CommonTestSuite")
            .getTestCaseByName("CommonTestCase")
    def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
    testCase.run(properties, false)
    

    This way your maintenance is confined to just a few places.