When cloning to another TestCase, I even noticed that the cloned TestStep receives the same name as the original TestStep.
Its name hasn't been changed!
A workaround is to
- Create a temporary TestCase
- Clone the original TestStep(s) to the new TestCase
- Change the name of the the cloned TestStep(s)
- Clone the renamed TestStep(s) to the original TestCase
- Remove the temporary TestCase
The following code creates new JDBC TestSteps for each SQL file in a specified directory (ResultSetsPath) based on a template step (ResultSetTemplateStep)
It then updates the query from the new step to the query in the SQL file.
//
// For every SQL file in the provided ResultStepsPath, clone the template TestStep with the filename as TestStep name
def tmpCloneTestCase = testRunner.testCase.testSuite.addNewTestCase("TemporaryCloneTestCase")
new File(ResultSetsPath).eachFile
{
// Ignore files that do not end in .sql
if (it.name.endsWith(".sql"))
{
// Make sure we can read the file
assert it.canRead()
// Get the new name for the testStep
String newStepName = it.name[0..-5]
// Clone the template TestStep
def newStep = ResultSetTemplateStep.clone(tmpCloneTestCase, newStepName)
newStep.setName(newStepName)
// Update the query of the TestStep with the contents of the file
newStep.setQuery(it.text)
// Now clone the temporary testStep to the original testCase
newStep.clone(testRunner.testCase, newStepName)
// Remove the temporary testStep
tmpCloneTestCase.removeTestStep(newStep)
}
}
testRunner.testCase.testSuite.removeTestCase(tmpCloneTestCase)
// Save the project
assert testRunner.testCase.testSuite.project.save() == true
However,it feels kinda nasty we have to do this :-)
Tnx!