Ask a Question

Accessing Test Case Property in Project's TearDown script

SOLVED
SuperSingh
Contributor

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 !

6 REPLIES 6
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

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
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.

 

 


Olga Terentieva
SmartBear Assistant Community Manager

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
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)}" 
		}		
}


Regards,
Rao.
TanyaYatskovska
SmartBear Alumni (Retired)

Thanks for the code, Rao.

@SuperSingh, is this what you are looking for?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



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

cancel
Showing results for 
Search instead for 
Did you mean: