Search code examples
asynchronousjmeterbeanshell

How to make async http request from jmeter while changing path dynamically before each call


Following are the steps that I need to peform

  1. Make http request call to a sevice which returns a json that has many urls.
  2. Extract all the urls using regular expression extractor
  3. Make http request call to all the exctracted urls asynchronously.

Is there a way we can achieve this? I tried parallel controller but, if I am not wrong, it requires all the request to be mentioned as its child sampler. I don't want to write each and every request manually. Is there a way we can change urls dynamically after running the test plan?


Solution

    1. It's better to use JSON Extractor if the server returns URLs in JSON format

    2. Once you have the URLs in form of JMeter Variables like:

      url_1=http://example.com
      url_2=http://example.org
      ........
      ........
      url_matchNr=X
      
      • add Parallel Sampler to your Test Plan

      • add JSR223 PreProcessor as a child of the Parallel Sampler

      • Put the following code into "Script" area:

         1.upto(vars.get('url_matchNr') as int, { index ->
             sampler.addURL(vars.get('url_' + index))
         })