Forum Discussion

SuperSingh's avatar
SuperSingh
Contributor
6 years ago

Accessing Test Case Property in Project's TearDown script

 Hi All, 

 

I was looking for groovy script to access property from test cases in the TearDown script (of Project)

On doing GetData simply returns " context.expand( '${#TestCase#TCCount}' )" [TCCount is the name of property]

I have multiple testcases but GetData returns TestCase when I try to load using ReadyAPI feature.

That's probably a bug in ReadyAPI

 

I tried by providing testcase name in place of "TestCase" but it does not return anything.

Can someone please provide an answer incase they have used this.

 

Thanks !

  • SuperSingh ,

     

    What you have shown is the Teardown Script of Test suite, but not the project level Teardown.

     

    /**
    * Below is the Teardown Script of the Test Suite
    * which looks for the given property in all the test cases of the same suite
    * and logs the value
    **/
    
    //Specify your property name in below statement
    def propertyName = 'Property1'
    
    testSuite.testCaseList.each { kase ->
    		if (kase.hasProperty(propertyName)) {
    			log.info "${testSuite.name} suite, ${kase.name} case, ${propertyName} value is ${kase.getPropertyValue(propertyName)}" 
    		}		
    }
    
  • richie's avatar
    richie
    Community Hero

    Hi,

     

    I dont know if I'm misunderstanding - but are you saying that you are unable to reference a property from another test case?

     

    I don't know if the following will help, but

     

    If it didn't pick up the property associated with the other test case - was you prefixing the testcase name with the testsuite prefix?

     

    I believe if you use the syntax as follows:

    context.expand( '${#TestCase#property1}' )

    The '#TestCase#' is actually specifying the level where the property is - not it's actual name.

     

    If you want to specify the TestCase name here - try the following:

    context.expand( '${#[TestSuite Name#TestCase Name]#property}' )
    

     

    Essentially i'm wondering if you specify the testsuite as well this might help?

     

    richie

     

    • Olga_T's avatar
      Olga_T
      SmartBear Alumni (Retired)

      Hi all,

       

      Thank you for your time looking into this, richie!

       

      SuperSingh, have you had a chance to try what richie suggested? If his guess was right and this helps you accomplish your task, could you please mark the above reply as a Solution? This will help other users find it faster when searching for the answer. Thank you in advance.

       

       

      • SuperSingh's avatar
        SuperSingh
        Contributor

        Hi richie

         

        Thanks for your time in giving the reply. The syntax you shared works when I put it individually.

        But I want to extract it from all the test cases. For e.g. if I have 5 testcases, I want to loop through all and extract the TCCount from their properties.

         

        The following piece of code doesn't work. But this is what I am looking to extract .

        testSuite.testCaseList.each {
        def name = "${it.name}"
        log.info name
        def tCCount = context.expand( '${'$name'#TCCount}' )
        log.info tCCount
        }

         

        Thanks again for your time .

         

        Regards,

        SuperSingh

         

  • nmrao's avatar
    nmrao
    Champion Level 3

    SuperSingh ,

     

    What you have shown is the Teardown Script of Test suite, but not the project level Teardown.

     

    /**
    * Below is the Teardown Script of the Test Suite
    * which looks for the given property in all the test cases of the same suite
    * and logs the value
    **/
    
    //Specify your property name in below statement
    def propertyName = 'Property1'
    
    testSuite.testCaseList.each { kase ->
    		if (kase.hasProperty(propertyName)) {
    			log.info "${testSuite.name} suite, ${kase.name} case, ${propertyName} value is ${kase.getPropertyValue(propertyName)}" 
    		}		
    }
    
      • SuperSingh's avatar
        SuperSingh
        Contributor

        Thanks nmrao  & richie  for your time.

        I was able to get the results with the help of your inputs. You guys rock !

         

        Sorry for the delay in response.

         

        Cheers !!!

        - SuperSingh