cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Test Case Property in Project's TearDown script

SOLVED
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 !

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Accessing Test Case Property in Project's TearDown script

@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.
6 REPLIES 6
Community Hero

Re: Accessing Test Case Property in Project's TearDown script

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 title of the post to something more descriptive? This will help people when searching for problems.
Moderator

Re: Accessing Test Case Property in Project's TearDown script

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

Contributor

Re: Accessing Test Case Property in Project's TearDown script

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

 

Community Hero

Re: Accessing Test Case Property in Project's TearDown script

@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.
Community Manager

Re: Accessing Test Case Property in Project's TearDown script

Thanks for the code, Rao.

@SuperSingh, is this what you are looking for?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: Accessing Test Case Property in Project's TearDown script

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

New Here?
Join us and watch the welcome video:
Top Kudoed Authors