Forum Discussion

chico-uspto's avatar
chico-uspto
Occasional Contributor
7 years ago
Solved

How to get the tag name assigned to a test case using a Ready API groovy script?

I would appreciate your help. I am using Ready! API version 2.1.
  • Nastya_Khovrina's avatar
    7 years ago

     Hi,

     

    Thank you for your post! There are the following methods for working with tags:
    at the project level: 
    * getTags()
    * getTagId("TagName")
    * getTagById(TagId)
    at the testCase level: 
    * hasTags()
    * getTagIds()
    * isTagAssigned(String tagId)
    Documentation: ​
    Class WsdlTestCase: https://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/testcase/WsdlTestCase.html
    Class WsdlProject: https://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/WsdlProject.html

    So, you can get tag names for a test case with the following script in the Groovy Script Test Step:

    import com.eviware.soapui.impl.wsdl.WsdlProject
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    
    def project = context.getTestCase().getTestSuite().getProject();
    def testCase = context.getTestCase()
    
    log.info testCase.hasTags()
    log.info testCase.getTagIds()
    
    def testCaseTagIdList =  testCase.getTagIds()
    for (testCaseTagId in testCaseTagIdList) {
       log.info project.getTagById(testCaseTagId)
    }