Ask a Question

[TechCorner Challenge #1] How to add a new tag and assign it to all TestCases in a TestSuite?

SmartBear Alumni (Retired)

[TechCorner Challenge #1] How to add a new tag and assign it to all TestCases in a TestSuite?

Hi Community!

As you know, we have a TechCorner label, a place where tons of useful information about ReadyAPI is stored. We would like to make this section even bigger.


I would like to encourage you to share more great content with all ReadyAPI community members under this label: use cases, tips, scripts, script templates, all the helpful things you are using in your daily testing with ReadyAPI.


Here’s one request that we get a lot from users,that you can help with:


Create a script, that can add a new tag and then assign it to every TestCases in a TestSuite


A link that will help you choose the right methods of working with tags at the TestCase level.


Tags are a neat feature of ReadyAPI, they help group TestCases and give more control over the testing process. This script is going to be very useful for ReadyAPI users. Who will contribute?🙂


Sonya Mihaljova
Community and Education Specialist

SmartBear Alumni (Retired)

Hint: This can be done in the following manner: add a new tag to a project using the addTag(String tagName) function and assign it to TestCases with the assignTag(String tagId) function.

Sonya Mihaljova
Community and Education Specialist

SmartBear Alumni (Retired)

Any script ideas?🙂

@avidCoder @groovyguy @richie @HimanshuTayal @nmrao 

Sonya Mihaljova
Community and Education Specialist

Community Hero

Don't have ReadyAPI. So never saw how it works.

But Had implemented tagging in Free edition long back using just test case custom properties. Of course, engineer assigns the appropriate tags (comma separated value) for each and every test case.


Here I wanted to raise a point that If a tag needs to be assigned to all test cases, IMO, there is no need to assign a tag at all. Because adding the same tag to all test cases does not achieve the purpose to filter the test cases(which is the main objective to have tagging). I believe this has to be something which engineer has to make a decision in which category particular test case belongs to such as smoke, regression, critical, customer issue etc.,


Task: Create a script, that can add a new tag and then assign it to every TestCases in a TestSuite.


This is a solution created for [TechCorner Challenge #1]


Here's a groovy script that will take a Test Suite name, and then iterate through each test case to add that name. Can be adapted to go through each test suite too, easily enough.



// set up project level variable
def project = context.testCase.testSuite.project;
String tagName = "DesiredTagName";

// Add desired tag name to project

// get tagId of added tag
String tagID = project.getTagId(tagName);

// set up desired test suite, by name.
def testSuite = project.getTestSuiteByName("test");

for (int i = 0; i < testSuite.getTestCaseCount(); i++)
	// get test Case object by index
	def tc = testSuite.getTestCaseAt(i);

	// assign the tag




Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

@nmrao But with the script they are asking for, it can teach someone HOW to add a tag to a project, test suite, and test case. From there, the seed is planted and a person and adapt the script as needed for their own devices. Certainly your point stands, if every test case has the same tag, maybe a tag is not necessary. But learning how to do it leads to learning how to use tags, and when/where/why/how.


Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

I am not sure the motive behind the script. Definitely people can explore the different options available.

May be it is more useful to highlight the tagging feature (than scripting if one needs to use it or play with it). Tagging is still a manual activity in my view and it is easily be tagged as when a new test case is added.
Kudos to your notice and writing and sharing the script.


Like already mentioned, Tagging is to filter out the tests that needs to be executed based on the need of the hour. Some one wants to run only customer issues or full regression or just smoke tests. As each set of tests take different time to complete, user can selectively execute the tests using the tags.


For those who are familiar with TestNG, it is called as grouping which is same as Tagging.

SmartBear Alumni (Retired)

Thanks for the script, Matthew!


Rao, as Matthew said, this should be a sample script demonstrating that users have the possibility to work with tags from script. It's possible to create a script that will check test cases only with certain names (or use some other parameters) and assign the needed tag only to them - this is an automatic procedure. Nothing will be done manually. As a result, you will get a project with a properly assign tags.


Again, this is one of the ways users can use to filter test cases to be run. I believe that your approach may work as well.



Tanya Yatskovskaya
SmartBear Community and Education Manager

May be I was quick to come a decision based on my predetermined understanding of tags. But, that is how some standard tools such as TestNG uses tagging / grouping of tests for executing different set of tests based on the tagging.


Isn't tagging used to filter the tests under execution in ReadyAPI?

If not, like I said earlier, I don't have the idea of tagging in context of ReadyAPI and how they work. May be I have to read a bit to get it.


Thanks for  clarifying note, Tanya.


Great post @groovyguy. Glad that you are active too 🙂

Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓

Thanks and Regards,
Himanshu Tayal
Showing results for 
Search instead for 
Did you mean: