Forum Discussion

aniket78's avatar
10 years ago

Problem in parsing SessionToken from XML/JSON response

For the Login test case, I are getting response in XML like below

<Response xmlns="http://accessconnector.com/api/1.0/OpenSession">
<SecureToken>o+SlOi5O0eFeKM9N1iMc/zVJAL/mKa+KOZvG7AMfqxIxzGtlLWRBVqFp2MG+4JuQ+M3qerZmETtrGdHyeX/lsyAWHe14K7V/smvgvaa9TN09tDrnxQQtPVN5yfZOoUXlImo7kxI1H07qMR5Kk8GvejB4/EvEnHV6fg7aQmQDvVCAg8eb0QdhqR1Z0inoAu8UsyOt8D81XtWTVE+YkN5undxbxfSjRUSyxkPJVcbk9bsC+irjdFpp/yQDtHsTUVyurGTtp1a9EVAIzL4XNyMvcn8rFaEOcJ3GwbQEhlQbDbxbWq+72mL5aMSvY25zh4+bPJkio1mfAjUQEHtAqUG+CQ==</SecureToken>
<SecureTokenExpiry>7/11/2014 11:57:03 AM</SecureTokenExpiry>
<SessionToken>c26f38e5-d9d4-448b-9d30-4cf5cca538e4</SessionToken>
<UserName>testdomain\testuser1</UserName>
</Response>

Or JSON response like below

{
"SessionToken": "c26f38e5-d9d4-448b-9d30-4cf5cca538e4",
"SecureTokenExpiry": "7/11/2014 11:57:03 AM",
"UserName": "testdomain\\testuser1",
"SecureToken": "o+SlOi5O0eFeKM9N1iMc/zVJAL/mKa+KOZvG7AMfqxIxzGtlLWRBVqFp2MG+4JuQ+M3qerZmETtrGdHyeX/lsyAWHe14K7V/smvgvaa9TN09tDrnxQQtPVN5yfZOoUXlImo7kxI1H07qMR5Kk8GvejB4/EvEnHV6fg7aQmQDvVCAg8eb0QdhqR1Z0inoAu8UsyOt8D81XtWTVE+YkN5undxbxfSjRUSyxkPJVcbk9bsC+irjdFpp/yQDtHsTUVyurGTtp1a9EVAIzL4XNyMvcn8rFaEOcJ3GwbQEhlQbDbxbWq+72mL5aMSvY25zh4+bPJkio1mfAjUQEHtAqUG+CQ=="
}

I need to pass session token for authentication in other test cases. But I am unable to pass the session token. Can i do it through Property Transfer? Or i need Groovy script? Can anybody help me here? I am using SoapUI 5.0.0 Free Version.

Thanks,
Aniket

1 Reply

  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi Aniket,

    what are exactly your requirements?
    You need that sessionToken as a TestCase Custom Property in your TestCases or do you need this sessionToken passed directly to your webservices?

    If you want to stored this sessionToken as a property in your TestCases, try this:

    String sessionToken = context.expand('${YOUR_AUTH_SERVICE#ResponseAsXml#//Response[1]/SessionToken[1]}')

    for (testSuite in testRunner.testCase.testSuite.project.getTestSuiteList()){
    for (testCase in testSuite.getTestCaseList()){
    testCase.setPropertyValue("SessionToken", sessionToken)
    }
    }


    If you need it as header in your REST webservices, try this:

    import com.eviware.soapui.support.types.StringToStringMap

    StringToStringMap header = new StringToStringMap()

    header.put("x-token", context.expand('${YOUR_AUTH_SERVICE#ResponseAsXml#//Response[1]/SessionToken[1]}'))

    for (testSuite in testRunner.testCase.testSuite.project.getTestSuiteList()){
    for (testCase in testSuite.getTestCaseList()){
    for (testStep in testCase.getTestStepList()){
    if (testStep.getConfig().getType() == "restrequest"){
    testStep.testRequest.setRequestHeaders(header)
    }
    }
    }
    }


    I hope it will help you

    Regards,
    Marek