Forum Discussion

pembertonrw's avatar
pembertonrw
Contributor
11 years ago

Clone Existing Test Case Via Groovy Script

I am using soapUI via the maven plugin and I am trying to do the following:
* Get a list of something via rest
* Iterate through the list and
** Clone a test case and rename it
** Run it
** Delete it

What I am struggling with is the cloning of the test case.

I can see that you can use the code:

import com.eviware.soapui.impl.wsdl.actions.testcase.CloneTestCaseAction

def slaveTestCase = testRunner.testCase.testSuite.project.getTestSuiteByName("Test Suite").getTestCaseByName("Name")
def ca = new CloneTestCaseAction();
ca.perform(slaveTestCase,Object)


but I can't seem to get how you can stop the prompt from appearing and just continue onto creating the test case.
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    The below code will clone a test suite named "Test" and rename it to "testing". Make the changes you need to fit your code and it should work fine. I wrote in Groovy so that I could efficiently test it but it shouldn't be difficult to grab the objects and use those functions.

    def testCase = testRunner.testCase.testSuite.getTestCaseByName("Test");
    testRunner.testCase.testSuite.cloneTestCase(testCase,"testing");


    To better fit your code:


    def slaveTestCase = testRunner.testCase.testSuite.project.getTestSuiteByName("Test Suite").getTestCaseByName("Name")
    testRunner.testCase.testSuite.project.getTestSuiteByName("Test Suite").cloneTestCase("NewName")
    • peti2005's avatar
      peti2005
      Occasional Contributor

      The last part will not execute because there is parameter missing in cloneTestCase().

       

      Tee following lines are correct:


      def slaveTestCase = testRunner.testCase.testSuite.project.getTestSuiteByName("Test Suite").getTestCaseByName("Name")
      testRunner.testCase.testSuite.project.getTestSuiteByName("Test Suite").cloneTestCase(slaveTestCase,"NewName")