Search code examples
javajmeterbeanshell

Download dynamic images concurrently


I need to download images concurrently.All the image url's have been extracted from one of the request's response.I used regular expression extractor to capture all the image urls.And ProfileImagePath_matchNr varies.

ProfileImagePath_1="www.mydomain.com/img1.png"
ProfileImagePath_2="www.mydomain.com/img2.png"
ProfileImagePath_3="www.mydomain.com/img3.png"
ProfileImagePath_4="www.mydomain.com/img4.png"
ProfileImagePath_5="www.mydomain.com/img5.png"
ProfileImagePath_6="www.mydomain.com/img6.png"
ProfileImagePath_7="www.mydomain.com/img7.png"

Now I need to download all those images concurrently.I could not able to use jp@gc Parallel http request as the ProfileImagePath_matchNr is varying.


Solution

  • You should be able to construct the list of URLs dynamically like:

    1. Add JSR223 PreProcessor as a child of the

    2. Put the following code into "Script" area:

      1.upto(vars.get('ProfileImagePath_matchNr') as int, { index ->
         sampler.addURL(vars.get('ProfileImagePath_' + index))
      })
      
    3. That's it, the PreProcessor will retrieve all the images URLs from the JMeter Variables and add them as the targets for the jp@gc - Parallel HTTP Requests sampler

    See Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn what do these vars and sampler variables mean