Hi,
I found a knowledgebase article that explained how I can use a groovy script step in a testcase to generate a random uuid:
// Generating a random variable value.
def uuid = UUID.randomUUID()
// Logging the variable.
log.info uuid
So I did that and when I run that particular script in my test case, I see a UUID is being generated properly.
What I would like is to be able to use this output which is stored in a variable called uuid in my next step which is a REST request. I need to pass the value of the variable in my resource path. How can that be done?
Thanks,
Gary
Solved! Go to Solution.
Name in bold should be same as the name of your properties test step:
testRunner.testCase.getTestStepByName("Propertes").setPropertyValue("uuid",uuid.toString())
correct it and you are good to go 🙂
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
@garymags : You can store the value in custom Properties as below 2 ways with in same groovy step :
1. by adding Properties step in your test case and storing the value in properties step by following code:
testRunner.testCase.getTestStepByName("Propertes").setPropertyValue("uuid",uuid.toString())
and then in your rest test step you can use : context.expand('${Properties#uuid}')
2. by storing value in test case custom properties by following code:
testRunner.testCase.setProppertyValue("uuid",uuid.toString())
and then in your rest test step you can use : context.expand('${#TestCase#uuid}')
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
@HimanshuTayal Hi Himanshu, thank you for your reply.
Sorry but I'm really new to Ready API so I was hoping you can confirm if I am doing this correctly. I provided screenshoots of my testcase. Can you tell me what I am doing wrong? I am trying to follow your first recommendation.
Gary
Refer attached screenshot how this should looks like,
On rest request part, your attached image in not getting open, please re-attach it or simple use below syntax where you want to use uuid
context.expand('${Properties#uuid}')
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
@HimanshuTayal Thanks again for your help. Much appreciated.
This is what my resource path looks like now based on what you explained. I need the uuid in that part of my resource path
/source-data/api/feeds/participants/context.expand('${Properties#uuid}')/complete
However, I am getting an error when it tries to run the added line in the Groovy script
java.lang.NullPointerException: Cannot invoke method setPropertyValue() on null object error at line: 7
@HimanshuTayal Hi, thank you so much for all your help. It is greatly appreciated.
It looks like the problem is the last line of the groovy script. I can run the groovy script separately and it generates a uuid. However, it has a problem when it gets to the last line of the script. I followed exactly what you had recommended to put in the groovy script but I'm still getting the error.
An error appears saying:
java.lang.NullPointerException: Cannot invoke method setPropertyValue() on null object error at line: 7
// Generating a random variable value.
def uuid = UUID.randomUUID()
// Logging the variable.
log.info uuid
testRunner.testCase.getTestStepByName("Propertes").setPropertyValue("uuid",uuid.toString())
Name in bold should be same as the name of your properties test step:
testRunner.testCase.getTestStepByName("Propertes").setPropertyValue("uuid",uuid.toString())
correct it and you are good to go 🙂
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
@HimanshuTayal Thank you so much. You are awesome!!
@garymags : I am so glad that it helped you in solving your problem 🙂
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
User | Count |
---|---|
7 | |
6 | |
6 | |
2 | |
1 |
Subject | Author | Latest Post |
---|---|---|