cancel
Showing results for 
Search instead for 
Did you mean: 

Set property at testsuite level access from all test cases

Highlighted
Not applicable

Set property at testsuite level access from all test cases

I have a situation where I want to use the date time as a test suite level property and can be accessed by all the test cases. This testsuite level variable must be constant for all the test cases throughout the run but each time the test suite is executed, it should create a new one.

Can you please detail out the step as to how to:

1. Create a property at the testsuite level
2. Access the property at each test case level

I saw something called setup script at the testsuite level but do not know how to use it to set and consequently access the property from the test cases.

Please detail out the steps as I am new to SOAPUI.

Thanks in advance.
4 REPLIES 4
Highlighted
Community Hero

Re: Set property at testsuite level access from all test cas

Yes, setup script at the test suite level is the one that suits your need.

Here is the script assuming that a COUNTER variable is being used in multiple test cases (one can have like ${#TestSuite#COUNTER} where required)


//first get the value of the property
def currentCounterValue = testSuite.getPropertyValue('COUNTER')
//increment value by one if already has some value otherwise set it to 0
def counter = (currentCounterValue) ? (currentCounterValue as int) : 0
counter++
testSuite.setPropertyValue('COUNTER', counter.toString())


Similarly you may use for date


Regards,
Rao.
Highlighted
Contributor

Re: Set property at testsuite level access from all test cas

Hi @nmrao

 

How do you set a new property in Setup Script at TestSuite level ?

 say, I want to create a property "Counter"  at Test Suite level via groovy. How do we do that?

 

I tried the following but it doesn't work.

testRunner.testSuite.setPropertyValue("Counter", "" )

 

Thanks,

SuperSingh

Highlighted
Frequent Contributor

Re: Set property at testsuite level access from all test cas

@SuperSingh, Setup script will not work if you use testrunner. as this object is not supported.

If you pay close attention to the UI it says "Setup Script is invoked with virtRunner, log,runner, context,testSuite variables"

 

So try: runner.testSuite.setPropertyValue("Counter", "PropValue" ) or

            testSuite.setPropertyValue("Counter", "PropValue" ) 

             

 

 

Highlighted
Community Hero

Re: Set property at testsuite level access from all test cas

It was already mentioned in my first reply, right? Have you tried that?


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 9
2 nmrao 6
3 HimanshuTayal 3
Top Kudoed Authors