I'm doing some testing with while controller.
In my test it checks every 3 seconds for a correct response text and if condition is not met, it repeats.
I would like to track how long that while controller was running, repeating itself until the condition was correct.
Is there any way to do that?
You do it via JMeter Functions, to wit:
__time() - to get the current timestamp before entering the While Controller
__longSum() - to calculate the delta between 2 timestamps
Something like:
Before the While Controller starts put the following expression somewhere in your script:
${__time(,before)}
It will store the current timestamp into ${before} JMeter Variable
After the While Controller ends put the following expression somewhere in your script:
${__longSum(${__time(,)},-${before},)}
It will get the new current timestamp and calculate the delta by substracting ${before} variable value from it
Demo:
See How to Use JMeter Functions posts series for more information on using JMeter Functions.
you can use Counter and Bean Shell Post Processor.
Keep Counter Config Element inside the While Controller. The value of Count will be incremented in each iteration.
So, in if condition, you can add BeanShell Post Processor to the sampler inside If controller, and calculate the total time taked using the following formula:
count value * 3 = total seconds waited to reach If Condition.
Following is the placement of elements in the TestPlan:
While Controller
...Counter
...If Controller
......HTTP Sampler
.........Bean Shell Post Processor
Image reference:
Counter Configuration screenshot:
Bean Shell Post Processor code:
int count = Integer.parseInt(vars.get("count"));
int totalTime = count*3;
log.info("total time waited : " + totalTime);
vars.put("totalTime", totalTime);
Screenshot:
Note: the value is saved in totalTime variable, so you can refer the value in subsequent requests using ${totalTime}
Related
I have below setup for my test plan:
In POST http request, I am sending a variable myCount set to value 0.
As per above configuration,
this test will run 100 times but everytime the value of myCount is sending 0.
I want it in incremental
for example: for loop 1 value set to 1, for loop 2 value should set 2.
Please let me know how can I achieve this.
Also, I would like to know in Taurus as well.
Thread Group has a pre-defined variable which returns the current iteration number, it's ${__jm__Thread Group__idx}
if you want the counting to start from 1 - go for __intSum() function
There is __counter() function which generates an incremented number each time it's being called
There is Counter configuration element which does the same but you have additional possibility to control the number format, i.e. if you need 0001 instead of just 1 or you plan to re-use the generated variable value later on within the bounds of same request or iteration. More information: How to Use a Counter in a JMeter Test
With regards to Taurus - in case of JMeter executor it supports all the approaches mentioned above
How can I pass 2 condition in a while loop on Jmeter. The conditions are
The request should run in loop till "Pass" response comes.
While loop should run only for 1 minute.
Condition 1 is working fine. However condition 2 is unable to implement.
I have tried running the While Loop inside a Runtime Controller. But the issue is, if the response "Pass" comes before 1 min, the rest of the test stops.
Tried other way round (Runtime inside While Loop) leading to numerous execution of the request, even after receiving "Pass" response.
Will appreciate any leads on this. Thanks
Add a JSR223 Sampler just before the While Controller and store the current time into a JMeter Variable using the following code:
SampleResult.setIgnore()
vars.putObject('whileLoopStart', System.currentTimeMillis())
Use the following __groovy() function as the While Controller's condition:
${__groovy(!vars.get('your_variable').equals('Pass') && ((System.currentTimeMillis() - vars.getObject('whileLoopStart')) < 60000),)}
This way the While Controller will run until:
either your_variable is not equal to Pass
or 60 seconds pass
whatever comes the first
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
This could be another solution.
You can achieve the desired outcome with the following components.
Runtime Controller
If Controller
Flow Control Action
Set the Runtime (duration) in the Runtime Controller
Set the first condition you already have in While Controller in the If Controller
Click the Break Current Loop to exist from the Run Time controller
MY response for api is:-
"data":{"shortId":"lu131559"}}
Now i wants to check short id is different for every virtual user.
mns if second hit gone response data is
lu131560
So i want to validate that after 1000 request from virtual user every time i am getting diff id.
If you know the "current" value of the shortId and expect it to be incremented by 1 each time you call your API you can go for Response Assertion and use __intSum() and __counter() functions combination in the pattern like:
lu${__intSum(131559,${__counter(,)},)}
Each time the Assertion will be called it will expect the value to be incremented by one, i.e.
lu131560 - for 1st user or iteration
lu131561 - for 2nd user or iteration
lu131562 - for 3rd user or iteration
etc.
More information: Apache JMeter Functions - An Introduction
i want to control my sampler execution by using a random variable . I have a sequence of hits login,welcome,Bla,log out . i want the log out to be performed for 6/10 requests and let others do not login(so to speak 6 requests will perform the whole sequence including log out, 4 of them will perform will not perform log out ).How to achieve the same in JMETER
I have added a random variable rand and set it between 1-10 at the beginning of the thread group .Then just above Logout sampler i placed an IF controller were i check ${rand}>4 . How ever i always get all sequence executed . Please suggest what am i doing wrong
Your approach is a little bit weird, my expectation is that the problem is in the following areas:
Your IF Controller condition is wrong (check jmeter.log file for any suspicious entries)
Your random variable setting is wrong, i.e. it has the same value for all virtual users (threads) so they will either be executed all or none
So I would recommend using Throughput Controller or Switch Controller in order to set up this 60/40 distribution.
See Running JMeter Samplers with Defined Percentage Probability article for more details.
Random Variable in Jmeter is saved in long format be default so
${rand} > 4 won't work. You need to change
Condition to ${rand} > 4.0
or change Random Variable Output format to 00 (2 digits)
see Manual
This was accomplished by creating a combination of config element- random variable and an IF controller
1) a random variable was created with Minim and maxim value to meet above condition
2) and IF controller was able to check ${myrand}>4;
This had derived the desired result - thank you all
Im using influxfb to save the result of my jmeter test.
bellow is the part of code in JSR223 Listener where im in need of your help.
result = new StringBuilder();
result.append("Thro_5,")
.append("label=")
.append(escapeValue(sampleResult.getSampleLabel()))
result.append("count=")
count=sampleResult.getSampleCount();
result.append(count)
result.append(",duration=")
dur1=sampleResult.getStartTime();
result.append(sampleResult.getEndTime()-sampleResult.getStartTime())
*****here code to write data to influxdb*****
I'm trying this code in which i want to know the total duration sample has taken till now to calculate throughput.
a=sampleResult.getEndTime()-sampleResult.getStartTime()
.append(",throughput_=")
.append(totalSamplecount/(a/1000))
Last line in the above code , i.e sampleResult.getStartTime() ,it should be the starting time of a sample in the first loop.
If i have 3 samples in my test ,having loop count 3 ,i want to save the starting time of each sample in the first iteration and use that value in the calculation of throughput of each samples.
Then while i'm in 3rd loop i want to know the total duration it has taken so far from the first iteration.And totalsamplecount/duration
As far as i know sampleResult holds the result of current sample.
I'm stuck in 2 points:
in saving the start time of each samples and use it later for each iteration to calculate the duration.
In saving the total count of individual samples executed till now.