Forum Discussion

jsontester's avatar
jsontester
Occasional Contributor
4 years ago

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?

  • 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

5 Replies

  • 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
    • jsontester's avatar
      jsontester
      Occasional Contributor

      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.

       
  • richie's avatar
    richie
    Community Hero
    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
    • ChrisAdams's avatar
      ChrisAdams
      Champion Level 3

      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.