Jmeter Variables Random in User and Email - performance

I need to do some performance testing and simulate 100 different users, but how do I make random variables for the user and e-mail?

You can use __RandomString() function to generate a random email, something like:
${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}#hotmail.com
the above function will return a random alphabetic string 10 characters long
Demo:
You can put __RandomString() function directly into HTTP Request parameters like:
The __RandomString() function calls will be substituted by generated random values in the runtime each time the functions are called.
See Apache JMeter Functions - An Introduction guide to get started with Functions in JMeter tests

Related

Unable to retrieve random DB values In JMeter

In JMeter, I am able to connect to DB and retrieve DB values.
I can view the DB_Value using variable which I specified in JDBC request(Variable Names field).
Example: with index of column value as CustomerID_1
I used BeanShell Sampler with below code:
${__BeanShell(vars.put("p_CustomerID_New","${CustomerID_1}"))}
with this p_CustomerID_New i am able to get db value and that works.
Now i have another random variable to replace above "1" with random numbers, so that i will be able to use different customers from DB and substitute in my API_Request.
When i use beanshell script with ${CustomerID}_${randomNo}, it only stores random number and CustomerID is not retrieved.
Any help would be much appreciated.
Thanks in advance.
You don't need to use any scripting at all, just to for __V() and __Random() function combination:
${__V(CustomerID_${__Random(1,${CustomerID_#},)},)}
According to JDBC Request Sampler documentation the following variables are getting generated when you run a Select statement:
Customer_ID_# - number of rows returned
Customer_ID_1 - value from the first row
Customer_ID_2 - value from the second row
etc.
So
${__Random(1,${CustomerID_#},)} function returns a random number between 1 and the number of returned rows
__V() function evaluates the generated expression and returns the random value
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
Going forward be informed that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
First of all using of Beanshell is deprecated and it is not a recommended to use it in Testplan.
It is recommended to use JSR223 pre/post-processor according to your needs.
I used pre-processor for the sampler - it works well
import java.util.Random;
Random rand = new Random();
def varName= "CustomerID_";
int randBoundary = rand.nextInt(100);// this will generate values between 0-100
varName = varName + randBoundary;
vars.put("p_CustomerID_New", vars.get(varName));
You can use this sample code and modify according to your requirements.

Same Token get generated for all thread - Jmeter

Case: First time default value will be used as accessToken and then extracted accessToken from response will be used. Using Regular Expression I have extracted the accessToken.
Problem: Same Token get generated for all thread.
Scenario:1 Number of Thread 10 and run; for all ten users default token get displayed.
Scenario:2 Number of Thread 20 and run. This time for 10 users unique token get generated; but for next 10 users default token get displayed. I have attached the JMX File https://filebin.net/qmsw7jkmwtu229rl.
Please correct me what I am doing wrong.
Don't inline JMeter Functions or Variables into Groovy scripts. According to JSR223 Sampler documentation:
JMeter processes function and variable references before passing the script field to the interpreter, so the references will only be resolved once. Variable and function references in script files will be passed verbatim to the interpreter, which is likely to cause a syntax error
So change ${__threadNum} function call in your Groovy scripts to ctx.getThreadNum() (where ctx stands for JMeterContext) and your approach should start working as expected.
Check out Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter

How to add key with unique random value in HTTP Request defaults in Jmeter

I am trying to apply load sample request is like
http://54.174.110.64:8080/adserver/html5/inwapads/?adFormat=preappvideo&ak=O4DCX2&version=1.0&adu=5&cb=1494853894218&output=vast&priority=1&size=[vdo_adSize]&pageURL=http://qa.vdopia.com/qa/Ruchi/ssp_preroll1.html?0.7888977&domain=vdopia.com&refURL=&category=[CATEGORY]&siteName=vdopia&displayManager=Vdopia-SPP-Web&di=[COOKIE_ID]&dif=fpcm&sex=[GENDER]&age=[AGE];ipAddress=203.122.9.130;di=abcdefghijklmn
I have single request, what I want is that same request should have unique di (last key in query param). Nothing else I want to change.
My test is based on unique di in request keeping other parameters constant.
You can use Random function.
Hint:
I would suggest using __UUID() function which will generate a GUID structure which is unique according to the underlying algorithm each time being called.
If you don't like dashes you can remove them via __groovy() function like
${__groovy("${__UUID}".replaceAll("-"\, ""),)}
Demo:
See Apache JMeter Functions - An Introduction to get started with JMeter Functions.
I have used below approach :
ad di=${di_random}in path of HTTP request

How to submit different value in same field for each user

I have a scenario in which user logon into system and submit some entry , but as system does not allow to submit duplicate records , i need to change on of filed value .
How this can be done , an sample code will be much more helpfull.
You have a number of options, feel free to choose the one which suits you best:
__threadNum() function - returns current user number, i.e. 1 for first user, 2 for second, etc.
__Random() function - returns a random number in the given range
__time() function - returns current timestamp in the different formats
__UUID() function - returns random (type 4) UUID structure - probably the most "unique" option
You can use functions anywhere in your test plan, i.e. directly as a parameter value.
See the following references:
Function helper dialog - a tool which helps to generate correct JMeter Function Syntax
JMeter Functions and Variables
How to Use JMeter Functions
you can map columns of a csv file with CSV_Data_Set_Config by setting variables names to : user,pwd...
after that you can use them to logon like this '${user}'

how to have a new value for each new user for time function in jmeter

I just wanted that ${__time(yyyyMMddHHmmss)} should have its new value for each new user in Http samplers
What I have tried is:
* Used loop controller
* Used counter config element
etc. but still unable to produce a new values for this time function
Regards,
AA
__time() function returns current timestamp either in milliseconds since Unix epoch start or according to pattern you specify. The function respects SimpleDateFormat patterns.
The weak point of your approach is that when it comes to high loads you can have more than one user calling this function at the same second you will get identical timestamps so I would suggest one of the following approaches:
Increase precision of your __time() function to milliseconds level like:
${__time(yyyyMMddHHmmss---SSS)}
Concatenate __threadNum() function with __time() function so each timestamp is followed by current virtual user number like:
See How to Use JMeter Functions posts series for more information on enhancing your JMeter tests with Functions.

Resources