Ask a Question

Execute existing testcase in Setup Script and get value from that response

Shashavali
Contributor

Execute existing testcase in Setup Script and get value from that response

Hi,

 

is there any way to execute existing testcase in Setup Script and get value from that response.

 

My scenario

 

Execute Login Test case as part of Setup Script of Test Suite. And from the response take value of token and store it Global properties. so that i can use that token in all the test cases. I tried the below but I am unable to retrieve the values from the response.

 

def tc =testSuite.getTestCaseByName( "VerifyPOSTAuthApi_Returns200OK" )
def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
tc.run(properties, false)
def response = context.expand( '$VerifyPOSTAuthApi_Returns200OK#Response}' ).toString()
def json = new JsonSlurper().parseText (response)

 

It is throwing an error at last line.

 

Thanks a lot.

 

Regards,

Shashavali

6 REPLIES 6
nmrao
Champion Level 3

Show your response and mention what data you need.


Regards,
Rao.

@nmrao Below is the response and i want to retrieve the value of token. And also i want to save the token value in the project property.

 

{
"pageNumber": 1,
"data": {
"userId": "abc@xyz.com",
"userSysId": 27,
"username": "username",
"email": "username@email.com",
"isActive": "1",
"orgId": 1,
"orgName": "Google",
"profileType": "LDAP",
"secretKey": "dsfadferw34324",
"LastPasswordUpdatedDate": null,
"key": "dsfdsaf",
"token": "eyJhbGciOiJIUzI1NiIsIfdsfdsfadaDFSAFERW3231231nR5cCI6IkpXVCJ9
}
}

@nmrao Below is the response and i would like to retrieve the value of token and store it as project property.

 

{
"pageNumber": 1,
"data": {
"userId": "sxy@gmail.com",
"userSysId": 27432423,
"username": "user",
"email": "sxy@gmail.com",
"isActive": "1",
"orgId": 1,
"orgName": "GoogleFB",
"LastPasswordUpdatedDate": null,
"key": "063db86af9006ab02013b1b90af54a4adf9067ae7a7596c8270d1a73e08977ed",
"token": "423144324werjouojlkkljoiewreyJhbGciOiJIUzI1NiIsI432EWRQ324234nR5cCI6IkpXV",
"userType": "HpUser"
}
}

nmrao
Champion Level 3

Thank you for the response.

Looks like you did not run the step and the response could be null. Hence you are not able to parse it with JsonSlurper.

First execute the step.


Regards,
Rao.

Thanks for the reply.

 

I think the below lines will execute the test case. I can see the response value in the HTTP Log

 

def tc =testSuite.getTestCaseByName( "VerifyPOSTAuthApi_Returns200OK" )
def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
tc.run(properties, false)

nmrao
Champion Level 3

@Shashavali,

change below statement from:
def response = context.expand( '$VerifyPOSTAuthApi_Returns200OK#Response}' )

to:

def response = context.expand( '${VerifyPOSTAuthApi_Returns200OK#Response}' )

and see if that helps.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: