Forum Discussion

Rish's avatar
Rish
New Contributor
6 years ago
Solved

How do you use a Groovy script to clone a TestSuite from one project to another?

I found the interface 

Interface CloneTestSuiteAction.Form

in the SoapUI API docs, but I am unsure how to use to it to implement the cloning.

 

The clone would be something like moving the TestSuite "Example" from Project 1 to Project 2.

 

Any help would be greatly appreciated. Thanks!

  • The challenge here is that the Test Suite probably refers to existing Interfaces (WSDLs, WADLs) in the source project, and in order for the copy to work in the new project, the interfaces need to be copied too.

     

    SoapUI does that for you when you right click and Clone Test Suite. And that right click action is what you get when you are using CloneTestSuiteAction from Groovy. It works, and I've included an example of this in the attached project file. 

    import com.eviware.soapui.impl.wsdl.actions.testsuite.CloneTestSuiteAction

    def sourceTestSuite = context.getTestCase().getTestSuite().getProject()
     .getTestSuiteByName("Simple TestSuite")

    CloneTestSuiteAction.cloneToAnotherProject (
        sourceTestSuite,
        "Destination project using original action",
        "New copy of Simple TestSuite",
        false, //move instead of copy?
        sourceTestSuite.description
    )

    Unfortunately it looks like that action is hard coded to prompt the user for some of the settings, so perhaps thats not what you wanted.

    It is possible to "steal" that same code and modify it to behave the way you want. And so in the attached project, I also show you how that's done with a script that clones the test suite without input from the user.

5 Replies

  • JHunt's avatar
    JHunt
    Community Hero

    The challenge here is that the Test Suite probably refers to existing Interfaces (WSDLs, WADLs) in the source project, and in order for the copy to work in the new project, the interfaces need to be copied too.

     

    SoapUI does that for you when you right click and Clone Test Suite. And that right click action is what you get when you are using CloneTestSuiteAction from Groovy. It works, and I've included an example of this in the attached project file. 

    import com.eviware.soapui.impl.wsdl.actions.testsuite.CloneTestSuiteAction

    def sourceTestSuite = context.getTestCase().getTestSuite().getProject()
     .getTestSuiteByName("Simple TestSuite")

    CloneTestSuiteAction.cloneToAnotherProject (
        sourceTestSuite,
        "Destination project using original action",
        "New copy of Simple TestSuite",
        false, //move instead of copy?
        sourceTestSuite.description
    )

    Unfortunately it looks like that action is hard coded to prompt the user for some of the settings, so perhaps thats not what you wanted.

    It is possible to "steal" that same code and modify it to behave the way you want. And so in the attached project, I also show you how that's done with a script that clones the test suite without input from the user.

    • Rish's avatar
      Rish
      New Contributor

      JHunt, firstly, I really appreciate you taking the time to provide such a concise solution to my question.

       

      I would like to offer some clarification regarding my projects and Test Suites. 

      The Projects that I'm working on are created by importing Swagger documentation. There are updates to this documentation over time, however since SoapUI Open Source does not allow you to re-import the Swagger documentation to the same project, I have to create new projects. However, the Test Suites that have been created in the previous Projects will always work in the new one (with the updated Swagger doc., mainly because there are only small updates), which is why I resort to MOVING the Test Suites using the Clone option.

       

      The question I posted was in an attempt to automate this cloning/moving. 

       

      Will your code still work for this scenario? 

       

       

      • JHunt's avatar
        JHunt
        Community Hero

        It will work in the sense that the test suites will be copied across to the new project, but they will bring their own interfaces across with them. They won't pick up the interfaces that you just imported from Swagger, so you'll have two similar interfaces in your new project.

         

        That might be okay for you?

         

        Otherwise you can have your script change the Interface for each TestRequestStep (use setRestMethod).