cancel
Showing results for 
Search instead for 
Did you mean: 

passing result or variable value from Groovy to test step

SOLVED
ravienu
Occasional Contributor

Re: passing result or variable value from Groovy to test step

Hi @nmrao ,

 

it worked with the way you suggested below.

 

Thank you very much and thank for giving relevant documentation links.

 

Thank you all who gave wonderful replies.

 

Cheers.

Ravi.

 

 

Tags (1)
jamesjack
New Member

Re: passing result or variable value from Groovy to test step

import groovy.json.JsonSlurper

testStep = testRunner.testCase.testSteps["YourApiRequestStep"]

def Response = testStep.getProperty("response").value;

def someFieldYouWantToSave = ""


if (Response == null) {
log.error('No Response found.');
}
else {
def jSlurper = new JsonSlurper();
def json = jSlurper.parseText(Response);
if (json.get("theFieldFromTheResponse") == null){
log.error "TheFieldFromTheResponse not found in response. Please execute the teststep and try again"
} else { omegle 
someFieldYouWantToSave = json.get("theFieldFromTheResponse").toString()

// YOUR LOGIC HERE FOR MODIFYING THE "someFieldYouWantToSave" value

//SAVE THE FIELD
testRunner.testCase.setPropertyValue("someFieldYouWantToSave", someFieldYouWantToSave)
}
} Thank you omegle chat 

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