How can i generate a coulmn value as a random value in a csv file while doing load test with Jmeter - jmeter

I am using Jmeter for load testing. I am passing parameters of the body from a csv file for an api. But our application will not receive the duplicate value. So when i load test by multiple users, the request get failed.because i am passing same parameter value for all users.So i need to make some of the columns with an instant value(random). so that different users will get different values.
{
"clinic_name":"clicnic",
"first_name":"provider1",
"initial":"v",
"last_name":"doc",
"salutation":"salu",
"address_1":"testttadd1",
"address_2":"testtttadd2",
"city":"ckdy",
"state":"Arizona",
"zip":"12365",
"fax":"",
"email":[{"email_id":"dfdf#dzcz.in","type":"Work","note":null}],
"phone":[{"number":"1235974444","note":"","type":"Mobile","extension":""}]
}
here i have given the request body and i need different email for different users. How can i do this?Can anyone help me..Thanks in advance.

you can use __RandomString function for the value of email_id:
"${__RandomString(15, abcdefghijklmnopqrstuvwxyz)}#${__RandomString(10, abcdefghijklmnopqrstuvwxyz)}.in"

The easiest is using Faker library like:
Download Java Faker jar and drop it to JMeter Classpath
Restart JMeter to pick the .jar up
You can use the following __groovy() function directly in the HTTP Request sampler body:
${__groovy(new com.github.javafaker.Faker().internet().emailAddress())}
Alternatively you can put the above expression into your CSV file, however make sure to wrap the variable reference into __eval() function, for example if you had ${email} you will need to change it to ${__eval(${email})}

Related

JMeter how to select randomely from a extracted set of values

I have a requirement to use randome url from a url list I extract from a json response.
Say I extract them in this mannser
imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4
In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely
("imageUrls_1","imageUrls_2",etc)
I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.
JMeter Is it possible to place a varibale inside a varible name?
Basically I need to use one of the extracted urls randomely in my HTTP request.
The easiest way is going for __V() and __Random() functions combination like:
${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Use __V function
${__V(url)}
The V (variable) function returns the result of evaluating a variable name expression.

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

How to Map RegEx variables with BodyData fetched from CSV Files

CSV Data Config from JMeter contains following -
File.csv Contains following
GetAllOrderItems.txt contains following
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
orderGuid_1_g1 is fetched from Regular Expression extractor
I passed following to JMeter body data
When I execute JMeter test, I can see follwing
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
However, I want ${orderGuid_1_g1} to be fetched from Reg Ex of previous HTTP Request.
I want following
{"dataRows":[],"orderGuid":"644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
Code works well, If i did not fetch Body data from text and directly insert below code inside body of HTTP Request
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
If your file contains nested JMeter Variables you need to wrap your __FileToString() function call in __eval() function like:
${__eval(${__FileToString(${GetAllOrderItems})})}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
JMeter does not interpret variables when you load content from a file.
Besides, for a load test using __FileToString function is not advised unless it is used for setup for example which is not the case here.
So just put the JSON Body request in the request body, it will be better for readability.
If you still want to do that, follow Dmitri Answer.

Jmeter how to read file path within csv file

Is it possible to pass in file path or read from another file within csv? My test setup is something like that.
Jmeter Test
Http request -> body data -> "items": "${__property(${items})}",
CSV data config
Id,Name,Items
1,MyName,\input\items_json.txt
I want to include a file in csv items column and in jmeter test, it will read and post items json.
Got it working with this.
"items": ${__FileToString(${__property(${Items})},,)},
Not really, being a Configuration Element CSV Date Set Config is initialised before anything else so you will have to consider another approach, i.e.:
__CSVRead() function
__StringFromFile() function
__FileToString() function()
Functions are being evaluated exactly where they're called so this way you can use them for parameterization. See Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept

HTTP Request path needs to be parameterized with UUID and a random URL

URL format is
www.something.com/something/api/{uuid}?code=gomundw0gjq2kbvc3g63whfr9usap5rurjaq5vui5vm6xbt9hhqa8hbcpto4yatwpn26v42t9
I need to make several calls to this GET Url and check performance of the feature.
uuid here is not just the UUID , but is specific to my application
UUID= accountid+identifierid+uuid, which will look like 1234+1234+123e4567e89b12d3a456426655440000
How should I arrange my Jmeter Test Plan.
My Plan would be:
write UUID generated to a file
Using any preprocessor call the file from file and write program to append to a different value in the csv which is account/identifierid.
Please help on this, can some one explain how I should logically arrange my test plan and code to get data to parameterize my path in HTTP Request sampler.
Thanks in Advance
You need to get accountid+identifierid information stored into CSV file. This is something you need to do on your own.
You can use CSV Data Set Config in order to get the information from that file while your test is running, example configuration would be:
UUID can be generated using __UUID() function
So your HTTP Request sampler configuration would be something like:

Resources