Forum Discussion

Parser's avatar
Occasional Visitor
8 years ago

groovy json property transfer



how do I set a Property like a SessionToken with groovy script, transfer this property and use it?



This is my script:



import groovy.json.JsonSlurper

// Get Request - sessiontoken ( json response)
//Call test step and print out the response as json string

def LoginStep = testRunner.runTestStepByName("Get SessionToken")
def response = LoginStep.getResponse()
def jsonStr = response.getContentAsString()

JsonSlurper serializer = new JsonSlurper()
def object = serializer.parseText(jsonStr)

responseContent = testRunner.testCase.getTestStepByName("Get SessionToken").getPropertyValue("response")
slurperresponse = new JsonSlurper().parseText(responseContent)
//set property
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue("session_token", slurperresponse.result.session_token) ("MyPropertyIs:" + slurperresponse.result.session_token)
//check session_token
//assert slurperresponse.result.session_token == false
//assert $.result.session_token != null

//print the count of array elements
//print each element of the array

// Post Request - post a new user (with json parameter)
def newUser = '"session":${=result.session_token}, "method":"User.Add", "params":{ "protUser":{ "userProt":{ "uid":19, "sUserName":"Test1","sPassword":"123456"}}}'

def addUserStep = testRunner.testCase.getTestStepByName("Add User")
def addUserRequest = addCommunicationPartnerStep.getTestRequest()

//test is prepared, now it can be called
testRunner.runTestStepByName("Add User")

// Check Request for add User


I'm getting the error:

Mon Nov 21 12:22:11 CET 2016:DEBUG:>> ""session":No such property: result for class: Script4, ...


No RepliesBe the first to reply