Skip to main content

JMeter: getting a value from the randomly selected variable

Assuming we have a CSV Data Source with multiple rows and 10 values in every row. We are parsing and storing the values into a set of variables, named var1,var2,var3,var4,var5,var6,var7,var8,var9,var10.

Now we can use these variables in any step using ${varN} reference. But what if we want to select a variable from this list randomly? So that one iteration would use var3, and another iteration would use var7, selected randomly.

I have used the following solution:

  1. Create additional user defined variable varTmp using "User Defined Variables" config element.
  2. Create "Random Variable" config element with variable name rnd, minimum value 1 and maximum value 10.
  3. Then use BeanShell PostProcessor that will store the value from randomly selected variable (var1-var10) into varTmp. We need to define two fields in the config element: 
  4. Parameters: ${__V(var${rnd})}
    Script: vars.put("varTmp", bsh.args[0]);
Now we can use ${varTmp} as a reference to the randomly selected varN variable.

Popular posts from this blog

Integrating TestRail and Gitlab CI/CD

Perhaps you are using Gitlab CI/CD at your project. Every project requires some test cases for regression testing, and Gitlab actually provides this feature, but it’s only available in Ultimate version that is more expensive. TestRail is another popular platform for managing your test suite that provides way more extensive capabilities and options than Gitlab’s own test case management feature. So the chances are that you are still willing to use TestRail for your acceptance and regression testing efforts. Why not combining the best of two worlds — the flexibility of Gitlab CI/CD and rich test case management capabilities of TestRail? In the following example I’ll demonstrate how this goal could be achieved with ease. Let’s assume that we need to create a new Milestone in TestRail that contains two test runs — the one with Acceptance tests, and another one with Regression tests. The step in your .gitlab-ci.yml Gitlab configuration file would look like this: This step is reading C...

Switching between keyboard layouts in Openbox (Arch Linux)

Switching between two (or more) keyboard layouts in Openbox DE is a task that's quite easy to accomplish, although it might not be so obvious as in other desktop environments. This solution was tested on Arch Linux. You just need to edit this file (assuming you want to switch between English and Ukrainian Phonetic layouts with Alt-Shift): /etc/X11/xorg.conf.d/01-keyboard-layout.conf Section "InputClass" Identifier "keyboard-layout" Driver "evdev" MatchIsKeyboard "yes" Option "XkbLayout" "us,ua(phonetic)" Option "XkbModel" "pc105" Option "XkbOptions" "grp:alt_shift_toggle" EndSection If you have Nvidia card, don't forget to edit /etc/X11/xorg.conf.d/20-nvidia.conf and change Driver from "kbd" to "evdev" in InputDevice section: Section "InputDevice" Identifier "Keyboard0" Driver "evdev" EndSection Y...

Using querySelector in Selenium WebDriver

Sometimes it's very helpful if we are able to click some element directly, by calling JavaScript click event. For example, this can be the case when the element is not visible, or not clickable, thus we cannot use native WebDriver methods. WebDriver driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.querySelector('.pane .object_options .dropdown-toggle span').click();");