Forum Discussion
- rupert_andersonValued Contributor
Hi,
Is it that for each execution of a TestCase you want to generate 1 random id and use it across more than one TestStep?
If so, in your TestCase:
1) Insert a Groovy TestStep as the first TestStep
2) in the Groovy TestStep generate a random number and store it in a property in the TestCase's context variable e.g.
context["randomId"]=random number code
3) You can than use the generated randomId property multiple times(in that execution of the TestCase) without its value changing. Use the property expansion syntax to reference itin requests etc e.g.
${randomId}
Make sense?
Regards,
Rupert
- nmraoChampion Level 3
Not sure if I understand completely.
Assuming below scenario:
- A test case - containing a step - which uses property expansion such as <element>${#TestCase#UNIQUE_ID}</element>
- And the case can be executed many times as needed.
In this case, I may even not use the random number, instead I would go for a sequence like below
- Define two custom properties, say PREFIX, UNIQUE_ID
- Set Initial Value for PREFIX as say Test1, can be any of your choice. this will help you identify different test sets. you can change it to Test2, Test3 as needed.
- Set Initial Value for UNIQUE_ID as 0.
- Add the below script as Setup script of the test case. This reads existing value and increments it by one and store it back.
def val = context.testCase.getPropertyValue('UNIQUE_ID') as Integer context.testCase.setPropertyValue('UNIQUE_ID', (val+1 as String))
In the test request of test case, use as <element>${#TestCase#PREFIX}_${#TestCase#UNIQUE_ID}</element>
The above would generate values incrementally as Test1_1, Test1_2 etc.,
NOTE:
This does not require any additional test steps
Coveat is that you need to run test case always in order to get the incremented value, not run as individual test step.
Hope this helps.
- diegomarconatoOccasional Visitor
My problem is that I use UNIQUE_ID several times in the SOAP request of the Test Case.
So it happens that I generate two different UINIQUE_ID. I want to create the same again UNIQUE_ID- rupert_andersonValued Contributor
So another way of saying what you want is when your TestCase is run:
- You want to generate a unique id (once per TestCase run)
- Then use that id multiple times in the same TestCase execution without the value changing.
- On the next run of the TestCase, a new id will be generated
Does this make sense and match what you want?
If so please see either my or Rao's answer. Mine uses a Groovy TestStep at the beginning, his uses a setup script - both achieve the same result.
Regards,
Rup
Related Content
- 5 years ago
Recent Discussions
- 2 days ago
- 2 days ago