cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
New Contributor

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!

5 REPLIES
Community Leader

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

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.

New Contributor

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

@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? 

 

 

Community Leader

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

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).

 

 

 

New Contributor

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

I get what you're saying. So is there no way to move the test suites and have it pick up the new interface generated by the new Swagger import (or just not move the original interface at all), using the script?

I'm guessing that's what happens when I move Test Suites between projects manually? 

 

Thanks,
Rish

Community Leader

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

No way for it tell which interface you would want to use. You could script it through.

Yes, it's the same as the moving action in the UI.
Share Your Stories
Read Latest News
Top Kudoed Authors