How to extract a number from response body in jmeter?



  • I am calling 2 different endpoints in my jmeter test. The first endpoint should provide me with a single number (for instance 568959) in its response body and then I must pass it to my second endpoint.

    Here is the response of my first endpoint:

    enter image description here

    please notice the response contains a single number, and it is not a json response as you see in image.

    and then I used a Regular Expression Extractor to extract this number from the body using a variable called newsId and regular expression as (.*) as below:

    enter image description here

    But, when I run my second request, I noticed it is sending an empty ${newsId} such as:

    https://www.example.com/blabla/rest/news//publish
    


  • Am not sure about how you are passing the Regex values to the second end point. But try this below method. It may work.

    After the Regex, add a Bean shell assertion and pass the variable newsId as

    ${__setProperty(newsId,${newsId})}
    

    Explanation : ${newsId} -> Pass the regex variable here in the setProperty.

    Now try passing the variable in the second end point. For reference please follow the below link.

    https://medium.com/@priyank.it/jmeter-passing-variables-between-threads-a4dc09903b59


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2