How to duplicate tests in Test Management 2.0

Community Alums
Not applicable

In Test Management 2.0, is it possible to copy a test so that you don't have to start from scratch when creating a similar test (in case only a few steps differ)? It was possible in Test Management 1.0 but that functionallity seems to be gone.

Thanks in advance

1 ACCEPTED SOLUTION

Community Alums
Not applicable

*I'm posting this reply again as it appears when the new community UI was rolled out this past weekend they didn't take the updates I posted from last week. 
 
I had the same business need. I've just had a play around and have a solution. 


I'll preface it by saying I'm very new to coding, so there may be a more efficient way to go about this, or you may find my code a tad messy. I can say, however, that my tests thus far with this solution are working as expected. 

 

In Test Management 2.0 when you create a new Test what you are doing is creating a new Version (check the table you are on when you hit 'New' from the Test UI Action). When a new Version is created, it also creates a Test record and associates it. 

 

I have created a new UI Action 'Duplicate' on the 'sn_test_management_test_version' table with the following script:

 

// Create new test version and in turn a new Test
var duplicate = new GlideRecord('sn_test_management_test_version');
duplicate.initialize(); 

duplicate.setValue('short_description', current.short_description + " 'Duplicated Test'");
duplicate.update();

// Find any steps which were on the test version 
var getSteps = new GlideRecord('sn_test_management_step');
getSteps.addQuery('test_version', current.sys_id);
getSteps.query();
while (getSteps.next())  

	// For each step found, copy it and set its Test Version to the new version created 
{ 
	var newStep = new GlideRecord('sn_test_management_step');
	newStep.initialize();
	newStep.setValue('test_version', duplicate.sys_id);
	newStep.setValue('step', getSteps.step);
	newStep.setValue('order', getSteps.order);
	newStep.setValue('needs_verification', getSteps.needs_verification);
	newStep.update();
}

action.openGlideRecord(duplicate); // Redirect to the new Test Version

 

 

This will copy all the steps of the version and put them into a new one. The state of the duplicated version will be set to Draft by default. The redirect takes you to the new Version where you can simply update it as desired, save it, and mark it as Ready. 

View solution in original post

7 REPLIES 7

Roxanne Mc
Tera Contributor

Yes, you may use "Insert & Stay" from the Additional Actions (Hamburger Button) menu

find_real_file.png

Worked like a champ and super easy solution. Thanks!

Community Alums
Not applicable

Keep in mind using 'Insert and Stay' on a Test does not copy the associated Test Version or its Test Steps. Similarly, if you 'Insert and Stay' on a Test Version, you lose all the Test Steps, and it orphans the Test Version. 

 

Using Insert and Stay in Test Management 2.0 is not advised.