Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use request value from list of values in JMeter

Tags:

I'm sure I've already done this in the past but somehow I cannot figure out how ;-) So, here's my problem:

I'm trying to create a JUnit test plan in which a HTTP request is modified each iteration by altering a specific parameter. So, for example in five iterations I want the following HTTP requests to be made:

http://localhost:8080/test/foo.html?id=1 http://localhost:8080/test/foo.html?id=2 http://localhost:8080/test/foo.html?id=3 http://localhost:8080/test/foo.html?id=4 ... 

I want to configure the identifier values globally for the test plan and use them within the HTTP request samplerer like this:

Path: /test/foo.html?id=${categoryId} 

The question now: How do I configure the identifiers values globally (I do not want to use StringFromFile) and how do I reference them in the sampler?

like image 322
Christian Seifert Avatar asked Jun 14 '11 09:06

Christian Seifert


People also ask

Can we extract value from request body in JMeter?

The value(s) which is extracted can be stored in any variable and can be a reference in any further request in the test plan. Values can be extracted from the response body, header, URL, response code, and other provided fields when you add this processor.

How do you select a random value from an array in JMeter?

The __Random function will give you an index for your interval. To obtain values from 1 to 5, you have to call __Random(1,6,) , as it will never reach the MAX value. The __V function, will obtain the value of the variable with the given name.


1 Answers

There are several ways you can do this.

  • If you're only incrementing, you can use a counter element
  • You can use any number of functions to calculate the value
  • You can read from a CSV file, which is the same effect as "StringFromFile" but easier to customize and manipulate

Given you have an array of values you could:

  • Try the pre-processor "User Parameters", creating one entry for each user/loop
  • Use a Beanshell script to create the array, select one at random and populate your variable

You reference them exactly as you have listed: ${varName}

like image 85
BlackGaff Avatar answered Sep 28 '22 11:09

BlackGaff