cancel
Showing results for 
Search instead for 
Did you mean: 

groovy json property transfer

Occasional Visitor

groovy json property transfer

Hello,

 

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)

log.info ("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
log.info(object.size())
//print each element of the array
object.each{
	log.info(it)
}


//***************************************************
// 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()
addUserRequest.setRequestContent(newUser)


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



//***************************************************
// Check Request for add User
//***************************************************
//todo

 

I'm getting the error:

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

 

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