cancel
Showing results for 
Search instead for 
Did you mean: 

groovy script to take session id from login test case and use it in other cases?

SOLVED
New Contributor

groovy script to take session id from login test case and use it in other cases?

 
1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: groovy script to take session id from login test case and use it in other cases?

'

In the groovy script, the previous step response can be read using below statement. Assuming the step name is step1, rename as per your need. Below script gets the sessionId and store it at test suite level (assuming that sessionId might needed across the test suite, if you want it for all suites, then you can even store it at project level, up to you).

 

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

holder = groovyUtils.getXmlHolder( "step1#Response" )

def sessionId = holder.getNodeValue( "//*:result/*Smiley Frustratedession" )

context.testCase.testSuite.setPropertyValue('SESSION_ID', sessionId)

 

Next step is to use the stored sessionId in various places: Property Expansion

In the other steps except groovy:

      ${#TestSuite#SESSION_ID}

In the groovy step:

     context.expand('${#TestSuite#SESSION_ID})



Regards,
Rao.

View solution in original post

4 REPLIES 4
Community Hero

Re: groovy script to take session id from login test case and use it in other cases?

The question has to be more precise, what steps are being used, if possible with a sample request / response involved and which values needs to be extracted etc.,



Regards,
Rao.
New Contributor

Re: groovy script to take session id from login test case and use it in other cases?

Hi,

I need to extract the session id field from the soap response and use it in other soap requests. I need a groovy script which does this automatically

 

<ns1:result>
<ns1Smiley Frustratedession>STVpJAutmzqKZ1PL5gaWQjqlAUgfKqodIm99pZkPz0kaXv_3coSUoGxYhpXpmUAUgd_t0Ub8hPa0MKjMvFFJ49qyDrGUWs3fFTBmA7Zq1hT6JCB_BoyD3ikS4NOT1e3aekZg6Cc41B5Id2VyZagnaR7xVAh7B9c9aSbn3tWOGOL_5pKql3PgneM_PIZYCfhtPIvREMxj2tp_83GLZD2CjzH_t_8kSMm9iOK8IQ2AMpVk1ZkjaKRk6WyxTqSIrshS</ns1Smiley Frustratedession>
</ns1:result>

 

Community Hero

Re: groovy script to take session id from login test case and use it in other cases?

'

In the groovy script, the previous step response can be read using below statement. Assuming the step name is step1, rename as per your need. Below script gets the sessionId and store it at test suite level (assuming that sessionId might needed across the test suite, if you want it for all suites, then you can even store it at project level, up to you).

 

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

holder = groovyUtils.getXmlHolder( "step1#Response" )

def sessionId = holder.getNodeValue( "//*:result/*Smiley Frustratedession" )

context.testCase.testSuite.setPropertyValue('SESSION_ID', sessionId)

 

Next step is to use the stored sessionId in various places: Property Expansion

In the other steps except groovy:

      ${#TestSuite#SESSION_ID}

In the groovy step:

     context.expand('${#TestSuite#SESSION_ID})



Regards,
Rao.

View solution in original post

Highlighted
Community Hero

Re: groovy script to take session id from login test case and use it in other cases?

You may also refer documentation for more details on Property Expansion here.
https://www.soapui.org/scripting---properties/property-expansion.html

Here is another resource on some code snippets.
https://www.soapui.org/scripting-properties/tips-tricks.html


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Final Interview in the Series
API_testing_mistake#7
Top Kudoed Authors