Jmeter random number generation - jmeter

I have a requirement to generate a random number and use it in subsequent requests. So, before using this newly generated random number in first subsequent request, i need to check if this random number generated is already exists in the application or not by comparing with newly generated response number. So for this validation i am thinking to use an extractor to get the count and eventually verify this is >1 and make it run until this condition is invalid. So in case of random number already exists, i need to generate a new random value since the previous one is already exist in the application. Any snippet i can use here?

An easier option would be going for __time() function which produces an Unix timestamp in milliseconds from 1st of Jan 1970. To be on the safe side you can add current thread number to it so even in case of concurrency you would get unique values (incrementing each millisecond):
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Related

How to update the array values from existing based on the condition and again pass same array with updated array element

We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's scope.

How to print iteration number in Pepper-Box plain text config?

I want to print iteration number in pepper-box plain text config and i tried Counter config element of jmeter but during execution it is not replacing iteration number. Like if i am using ${counter} so in execution it is printing ${counter}.
I am using counter config element because i need iteration number in some format like 00001,00002,00003 etc.
I also tried to use function like Counter(TRUE,) but it is just replacing first iteration number and not increasing it. Only first iteration number printing in all next iteration.
In Pepper-Box sampler you can only use a limited subset of built-in template functions having different syntax.
You can try doing something like:
{{org.apache.jmeter.threads.JMeterContextService.getContext().getVariables().get("counter")}}
or if you want to share your script with others you can consider implementing a custom function
Check out Apache Kafka - How to Load Test with JMeter article for more information on building a Kakfa test plan using JMeter

Avoid failed cases in jmeter

I am running jmeter to perform performance testing on a web application. The web application restricts the creation of the duplicate task. When I record that using blazemeter and run it with 100 threads, it shows that the task creation url is failed in the report, as it tries to create a task with the same name. How to avoid this?
In the majority of cases you simply cannot record and replay JMeter script without prior modifications as you need to perform correlation and parameterization.
In particular your case you need to identify the task id, most probably it is a parameter of a POST request and replace recorded hard-coded value with a JMeter Function which will generate a random value, i.e.
__Random() - for a random number in the given range
__RandomString() - for a random string from the given characters
__UUID() - creates a GUID-like structure with a very high chance of being unique, i.e. 123e4567-e89b-12d3-a456-426655440000

How to asssign one random variable to multiple threads in J-Meter?

I need a new "ROOMID " every time I run a test. I setup a random variable generator to give me a new ID each time the test is run. However, if I set the number of threads to 5 it gives a different ID for each one. I need it to use the same one for each thread. I only need it different each time I run the test.
I know it is occurring because I am calling the variable listed in the Random Variable Generator. Is there anyway to just get 1 random conference ID for all the threads?
Example
Random Variable Generator creates an ID.
Do an HTTP request and set it to run five threads:
1st gets 123456
2nd gets 234567
3rd gets 7451236
4th gets 4452189
5th gets 1254866
I need all of them to receive 123456.
Then the next time I run the test I need them to all get a different ID.
Please follow the below steps to generate random number to be constant across threads.
In the Test Plan, create a variable myVar and set the value as ${__Random(1,999999,)}. You can configure the maximum value in the random function.
In Thread Group enter the number of threads as 5 as shown below.
Execute the script. In View Results Tree or Debug Sampler you can view the value of myVar which is constant across the threads.

Need to add unique value every time when run the POST api request in jmeter

Need to add unique value every time/always when run the POST api request in jmeter. I have API which is POST request, this request added 'roleId' which should be unique every time (should not use the id which was already created). I have tried below options but response says duplicate id.
1. Add http request with POST body> add 'Counter' to this request with min: 25 and max: 50 with increment:1
When run the request it always starts with '25' and it fails from the second run as it says duplicate value because in the first run this id has been inserted in table
2. User defined variables: used __Random function but for this also same issue.
3. CSV data set config: same issue.
Please suggest what would be the best approach to solve the issue.
__UUID function can generate a GUID structure which is pretty much unique, something like: 9e73f1a6-c1dc-44f7-b73a-508871f98b83
__time() function can generate current timestamp in milliseconds from the start of the Unix epoch, something like 1492417676453 (it won't help if you have > 1 request in millisecond)
__threadNum() function returns current virtual user number
__iterationNum() function (available via JMeter Plugins) returns current loop number (thread group level)
__counter() function which generates an incremented value each time it's being called
You can use any combination of the above in order to generate your roleId, if you have doubts let us know the criteria so we could come up with the best solution. In the meantime check out Apache JMeter Functions - An Introduction article series to get the overall idea about using Functions in JMeter tests.

Resources