JMeter loop through different Test Methods - jmeter

I want to test my REST service within one Test Plan and one Thread Group.
There are two methods. Let's call it getConfiguration and getDefinitionList. Both have different parameters in the URL and as header. That's why I created a CSV file for both of them. The first CSV file contains five lines for the different test cases, the second only three.
I added a CSV Data Set Config to both methods.
I want JMeter to perform the first method five times and then the second, three times. Then the thread is to be terminated.
Without an additional controller, the first method is executed once, then the second one, then the first and so on. With the second one there are of course errors, because the CSV file has only three lines.
I thought a loop controller might help, but can't get it right

Well,
Put your 1st method under Loop Controller and set Loop Count to 5
Do the same for 2nd method, but this time set Loop Count to 3
Move CSV Data Set Config elements as children of the HTTP Request methods

You need to nest each CSV Data Set Config inside the While Controller due to Scoping rules:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
And set sharing in CSV Data Set config to Current Thread Group
Example:
CSV Data Set configured like this , pay attention to each config:
While Controller1 condition :
${__jexl3("${name1}" != "",)}
While Controller1 condition : ${__jexl3("${name1}" != "",)}
${__jexl3("${name2}" != "",)}
If Controller1 condition and check "Interpret Condition as Variable Expression":
${__jexl3("${name1}" != "",)}
If Controller2 condition and check "Interpret Condition as Variable Expression":
${__jexl3("${name2}" != "",)}

Related

Can a request parameter extracted from response of previous request have different values when run multiple times - Jmeter

Scenario:
We are extracting a value from 1st request and passing it as a parameter for the 2nd request.
The 2nd request is in Loop controller and it is run multiple times, But every time the 2nd request runs , It should take different value. Is there any way to do this.
Eg: Below is the example screenshots for the same. data is the variable which is passed to the second request .When second request is hit multiple times , It should extract different values.
In the Regular Expression Extractor set "Match No" to -1 to you will extract all the matches into:
data_1=1
data_2=2
etc.
In the Loop Controller set the "Loop Count" to ${data_matchNr}. This way the controller will iterate as many times as there are matches in the Regular Expression Extractor
Instead of ${data} use ${__V(data_${__intSum(${__jm__Loop Controller__idx},1,)},)}
More information: Here’s What to Do to Combine Multiple JMeter Variables

How can i generate dynamic sequence number of transaction controller

Usecase :- I have one thread group. Inside this i have one loop controller. In loop controller i have 120 transaction controller. During debugging of the script it creates confusion to find the failed steps. I want to put some variable for dynamic number generation. I did it by using Beanshell Sampler as following:
After this i used beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} inside the name of transaction controller. It works for me.
I want to use variable name in place of Beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} function. How can i do that?
You can use loop controller index (add +1 if you want to start with 1)
${__groovy(${__jm__Loop Controller__idx}+1)}
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named LC, then you can access the looping index through ${__jm__LC__idx}. Index starts at 0

JMeter - How to pass data from the CSV Data Set Config to the ForEach Controller

My .csv file contains only one column called domain
I have very simple script:
Thread Group
CSV Data Set Config
Debug Sampler - ${domain}
ForEach Controller (in has input variable domain and output variable out)
Debug Sampler - ${out}
It executes the first Debug Sampler but not the second one.
I assume that ForEach does not get the domain variable from the CSV Data Set Config.
Please help.
you are using the For Each Controller in the wrong manner. basically, it expects the input as a list of values, which can be accessed using domain_1, domain_2 etc where domain is the value defined in the Input variable prefix field. This controller is primarily used with the combination of Reg Ex Extractor, which gives similar out (list of values) and accessing mechanism of them (using domain_1).
In your case, domain_1 & domain_2 are not defined, samplers inside won't be executed.
So, you must create/provide the input in the format For Each Controller expects Or use other controllers like While Controller etc.
Note: In order to provide the list of values as For Each Controller expects from CSV file, you can define more columns as follows:
domain_1,domain_2,...domain_n
google,yahoo,...bing
so, you can define Input variable prefix as domain, and make domain_1 & domain_2 variables available to the For Each Controller (As defined in the column fields).

How can I use the value of prev HTTP Request to the next HTTP Request in jMeter?

I'm newbie in jMeter and I'm working with it.
I have one Thread Group which consists of two Loop Controllers.
In 1st Loop Controller, there's a HTTP Request which contains body data
{ ..., "var1": "var-${__RandomString(10,1234567890abcdefg)}", ... }
In 2nd Loop Controller, there's also another HTTP Request that contains var1, and I want to asssign this var1 with same value as the prev var1 in the 1st Loop Controller.
I have tried use User Defined Variables, but it generated same value for another Thread Groups, I want generate different value of var1 for each Thread Group.
Can anyone help me what should I do to make it works? Thank you :)
Add Post Processors --> Regular Expression Extractor to the Http Request which you want to fetch the variable named var1.
As the above picture is shown use "var1": "(.+?)", as Regular Expression. The (.+?) part defines that Hey! Regular Expression Extractor, please fetch for me whatever is between "var1": " and ",, which you'll find in the response content. So var-${__RandomString(10,1234567890abcdefg)} would be fetched into a variable named Var1 (Because you defined Var1 as the Reference name.
Then, in the Http Request where you want to access that variable, use ${Var1} in order to send the value of Var1 variable as a request parameter. Something like the picture below
Note that the last value in the loop will be saved in Var1. If you want to save all values in the first loop in order to use those in the second loop,There's many way to do that.
You can add a Counter from Config Element to the first loop Controller and define for example loopCounter as the reference name for it. Fill the start and increment fields with 0 and 1.
Then change the regular expression to Var${loopCounter}
In the next loop's Http Request you can access these variables with ${Var1}, ${Var2} and ...
Just change your __randomString() function to look like:
${__RandomString(10,1234567890abcdefg,var1)}
it will overwrite ${var1} with random generated value so you'll get the same random string in both loop controllers.
See How to Use JMeter Functions articles series for more information on the above and other functions.

JMeter: Can't copy CSV variable into another variable

I am reading a token from a .csv file into variable CSV_ACCESS_TOKEN. I have 3 request under one ThreadGroup. I want a scenario when logged in user loads a page thrice (or N time). So 1 thread is looping N time. After reading token once, I dont want to read next token in loop but want to loop through URL three (or N) time with same token.
Right now I am reading data from CSV, and using "BeanShell Sampler" inside "Once only Controller". In the sample I am using line like: vars.put("ACCESS_TOKEN",vars.get("CSV_ACCESS_TOKEN"). But that BeanShell sampler is recorded in my Summary Result. I don't want that.
I tried using "User Defined Variable" controller and try to assign the value ${__evalVar(CSV_ACCESS_TOKEN)} but it return empty value for ${ACCESS_TOKEN}. When I use ${CSV_ACCESS_TOKEN}, it shows me the values. If I use some other variable instead of CSV_ACCESS_TOKEN in UDV controller, it assigns the value from other variable and I see values for ${ACCESS_TOKEN}.
Why CSV variable is not assigning the values in regular variable.
Thanks
Vinay
If you have 3 requests, I suggest you put a Beanshell preprocessor on the first request, which copies the CSV_ACCESS_TOKEN to ACCESS_TOKEN.
Each of your samples can the use ACCESS_TOKEN, so CSV is accessed once per cycle of 3.
Each time the preprocessor run (ie before each 1st request), CSV_ACCESS_TOKEN will get updated from the dataset.
If it is the same request, which you do not wish to duplicate, you can look into use of test fragments and modules, so you can run the same sample from a variety of controllers. First from a simple controller with the preprocessor attached, and then from a loop controller to perform 2 more requests.
I think the code you have used already to manipulate the CSV values will continue to work in this scenario.

Resources