cancel
Showing results for 
Search instead for 
Did you mean: 

Using partitial value in a request

SOLVED
jsontester
Occasional Contributor

Using partitial value in a request

I want to use partitial value in my request from a earlier response. I can use tranfer property or use get data but then I get the whole value and not a part what I need in my request.

 

As example: In a earlier response I have value 00123456789 in a property "id"

Now I want to use the first 8 digits in my next request. That's 00123456

 

How can I use a part of the value in my request?

1 ACCEPTED SOLUTION

Accepted Solutions
HimanshuTayal
Community Hero

Re: Using partitial value in a request

@jsontester : You can use below code sample, it is the implementation what @richie  has suggested you

 

import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Response")

slurperRes = new JsonSlurper().parseText(response)
def val = slurperRes.PATH__TO__VALUE

def desired_Val = val.take(8)
log.info desired_Val

Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

5 REPLIES 5
richie
Community Hero

Re: Using partitial value in a request

Hey @jsontester,

In your test you can save the value into a properties step, and use a groovy step to truncate the value you want using the split() method.

Im busy with work right now, but if someone doesnt beat me, i'll dig out the groovy to do this tonight.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
ChrisAdams
Contributor

Re: Using partitial value in a request

Hi,

 

@richie is right here.  Though, one suggestion would be to do away with the property transfer, it's not required.

 

Personally, I'd stick a groovy step in between the two test calls.  The Groovy step would be invoked by the second step.  The groovy can read the value from the first call, manipulate and return the manipulated value directly into the payload of the second test call.

HimanshuTayal
Community Hero

Re: Using partitial value in a request

@jsontester : You can use below code sample, it is the implementation what @richie  has suggested you

 

import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Response")

slurperRes = new JsonSlurper().parseText(response)
def val = slurperRes.PATH__TO__VALUE

def desired_Val = val.take(8)
log.info desired_Val

Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

jsontester
Occasional Contributor

Re: Using partitial value in a request

thanks for the solution. I'll click "Accept as Solution"  if it works. I can't identify the correct paths when I select GET data from a rawrequest now.

 
HimanshuTayal
Community Hero

Re: Using partitial value in a request

@jsontester : If it is allowed please post your json here or DM me i will be happy to help 🙂

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors