Forum Discussion

markgholland's avatar
markgholland
Occasional Contributor
9 years ago

Delete Test Suite (and test cases) via groovy script?

Hi,

 

I've searched everywhere and tried SEVERAL approaches, but I haven't had any luck with any of them.  Hoping someone may be able to help me out!

 

Here is what my test case looks like:

The test step, "Create New Generate Report Requests" creates the "GenerateReportUS" test suite, test cases(I know there is a duplicate name, this would never happen with a full execution), and test steps for each test case.  Here is the code in the step that checks to see if it already exists, where I'm stuck:

//see if 'GenerateReportUS' suite exists
genReportTS = context.testCase.testSuite.project.getTestSuiteByName("GenerateReportUS")
if ( genReportTS != null ) {
	//if exists remove test suite and all test cases
	//stuck here!!!
} else {
	//create 'GenerateReportUS' suite
	context.testCase.testSuite.project.addNewTestSuite("GenerateReportUS" )
	genReportTS = context.testCase.testSuite.project.getTestSuiteByName("GenerateReportUS")
}

The reason I'm doing it this way instead of just iterating through the test data is that the request that is being created takes ~30-60 seconds to run depending on size of the test data and there are 50+ iterations, so I want to speed up the execution time.

 

Thanks in advance for your assistance!

 

  • Though I've not actually had to do this myself, but assuming that your project object is of the class WsdlProject I think you can just use the following line in your if statement: 

     

    testRunner.getTestCase().getTestSuite().getProject().removeTestSuite(genReportTS)

     

    Note: The remove method does not appear in the Groovy editors code completion, but I've seen that a lot. I've always found it easiest to refer the JavaDocs

  • Radford's avatar
    Radford
    Super Contributor

    Though I've not actually had to do this myself, but assuming that your project object is of the class WsdlProject I think you can just use the following line in your if statement: 

     

    testRunner.getTestCase().getTestSuite().getProject().removeTestSuite(genReportTS)

     

    Note: The remove method does not appear in the Groovy editors code completion, but I've seen that a lot. I've always found it easiest to refer the JavaDocs