cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a new tag and assign it to all TestCases in a TestSuite?

SOLVED
Highlighted
Community Manager

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
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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
project.addTag(tagName);

// 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
	tc.assignTag(tagID);

}



---

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

View solution in original post

10 REPLIES 10
Highlighted
Community Manager

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Manager

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

Any script ideas?🙂

@avidCoder @msiadak @richie @HimanshuTayal @nmrao 


Sonya Mihaljova
Community and Education Specialist
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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



Regards,
Rao.
Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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
project.addTag(tagName);

// 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
	tc.assignTag(tagID);

}



---

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

View solution in original post

Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

@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!
Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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.



Regards,
Rao.
Highlighted
Community Manager

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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 Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Hero

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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.



Regards,
Rao.
Highlighted
Community Leader

Re: Your Ideas Required - How to add a new tag and assign it to all TestCases in a TestSuite?

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


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors