Execute existing testcase in Setup Script and get value from that response
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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"
}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
