cancel
Showing results for 
Search instead for 
Did you mean: 

How to get data from raw response and set it as property for test case by groovy

SOLVED
Highlighted
New Contributor

How to get data from raw response and set it as property for test case by groovy

Hi Bears,

From my request I'm only able to receive RAW response with data:

HTTP/1.1 201
Date: Thu, 06 Jun 2019 23:02:56 GMT
Content-Length: 0
Connection: keep-alive
Location: https://xyz.yoyo.bro/3999a180baa54dd68a627d2ed1b16500
cartId: 3999a180baa54dd68a627d2ed1b16500
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY

 

I would like to take this cartId, and set it as a property for next steps from my test case.
I was trying with testRunner etc. but it gaves me only a lot of errors.
If anybody have some idea, I will be very grateful for answers and tips.

1 ACCEPTED SOLUTION

Accepted Solutions
New Contributor

Re: How to get data from raw response and set it as property for test case by groovy

Hello Rakinson33, 

 

Can you try with this groovy script?

 

// Get the cartId header
def cartId= testRunner.testCase.getTestStepByName("TestStep").httpRequest.response.responseHeaders["cartId"][0]

// Set a test case property for the header
testRunner.testCase.setPropertyValue( "cartId", cartId)

 

Regards

2 REPLIES 2
New Contributor

Re: How to get data from raw response and set it as property for test case by groovy

Hello Rakinson33, 

 

Can you try with this groovy script?

 

// Get the cartId header
def cartId= testRunner.testCase.getTestStepByName("TestStep").httpRequest.response.responseHeaders["cartId"][0]

// Set a test case property for the header
testRunner.testCase.setPropertyValue( "cartId", cartId)

 

Regards

New Contributor

Re: How to get data from raw response and set it as property for test case by groovy

Thank You SorinC,

This solution is fine when we are using 'groovy script' as a next test step. 
I was trying to achive this option as a assertion script in my first request which produce this cartId.

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