How to hit parameterized url in Apache Jmeter? - jmeter

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.

Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.

You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}

Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

Related

how to pass the dynamic filename in csv data set config in jmeter while the dynamic names are generated to save data of previous request?

I have one http request whose response comes in nested json and using groovy i am saving that data in different csv file on the basis of conditions.
the name of csv file is generated dynamically and saved in a variable
using vars.put() function
vars.put("_cFileName",cFileName.toString());
when try to use this variable in csv data set config
enter image description here
getting error message
2022-01-19 16:58:39,370 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.IllegalArgumentException: File ${_cFileName} must exist and be readable
it is not converting the name to actual file name
But in case if file name is not dynaamic and the variable is defined under user defined variable in test plan it will able to convert to actual file name?
is there any way we can use the dynamic name created in an previos request post processor?
You cannot, as per JMeter Test Elements Execution Order Configuration Elements are executed before everything else, CSV Data Set Config is a Configuration Element hence it's being initialized before any JMeter Variables are being set.
The solution would be moving to __CSVRead() function, JMeter Functions are evaluated at the time they're being called so it's possible to provide dynamic file name there, see How to Pick Different CSV Files at JMeter Runtime guide for more details if needed.

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 run multiple urls in jmeter and it should display on one screen

i am new to jmeter. i would like to run multiple urls at one shot and display the results on one screen. finding hard to config urls through csv file and in jmeter.
my sample url:
http://10.56.34.67:7065/services/sample/2070
http://10.56.34.67:7065/services/sample1/2070
http://10.56.34.67:7065/services/sample2/2070
like this i have more thn 100 url to test it.
could you please tell me the format to store urls in csv file and how to config the csv file in jmeter?
It has simple as
Click Ctrl+0,Ctrl+1 which adds Thread Group and HTTP Request in side
In HTTP Request add ${path} to Path field
In Thread Group choose Loop Count Forever
Add CSV Data Set Config by right click on Thread Group -> Add -> Config Element
CSV Data Set Config parameters :
a. Put the fileanme in Fileanme field
b. Enter in Variable Names path
c. Choose Recycle as False
d. Choose Stop Thread as True
Click Ctrl+R (run)
It will go through all URLs and submit them sequentially
To view results you can add View Results Tree (Click Ctrl+9) and you will see all your requests/responses.
It seems your data here is your URLs.
So instead of using multiple samplers for each URL, you can go for CSV Data config and store all your URLs there and name the column as URL.
you can refer to this in your single http sampler as ${URL}.
Your CSV should look like this
In Server name put ${URL} and in the Thread Group check the forever check box
You don't need CSV for this use case, the easiest way would be going for __StringFromFile() function.
In the HTTP Request sampler put the __StringFromFile() function into "Path" input field like:
The textual function representation is ${__StringFromFile(urls.txt)}, you will need to replace urls.txt with full or relative path to the file where your URLs are listed
That's it, each time the request is called JMeter will read the next line from the file and substitute request path with the string from file:
See Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept

Passing Multiple JSON parameters in JMeter

My registration form is accepting body in JSON format, and I need to run the test with 5 different user names.
How do I pass JSON as request body? Also I was unable to pass parameter from CSV file. How can I solve this issue?
Add CSV Data Set Config to your Test Plan
Configure it like:
Filename: full path to the file with your emails
Variable Names: anything meaningful, i.e. EmailId
In your HTTP Request sampler copy the recorded value to Body Data" tab and replace hard-coded email with JMeter Variable like:
{"EmailId" : "${EmailId}"}
In Thread Group set "Number of Threads" to 5
Next time you run your test JMeter will read next line from the file.csv and substitute the ${EmailId} variable with the value from the CSV file.
See Using CSV DATA SET CONFIG article for more information on parameterising your JMeter tests via CSV files.

Automatically generate HTTP request URLs in JMeter

I have an API call URL similar to this:
http://domain.com/rest/getValues?apiKey=sdfsdf&customerId=2200&timestampBegin=2013-08-15%2018:00:00%20CEST&timestampEnd=2013-08-19%2018:00:00%20CEST
I would like to dynamically change the time stamps, as well as the customerId, picked from a given set of timestamps and customerIds. Is this possible to do in Jmeter (preferably through GUI)?
Assuming that you are have inputs coming from external CSV file, you can use CSV data set config as explained here.
Your test plan will look something like
Thread groups
CSV Data Set config (define the file path and the variable names. You will be able to read these variables in request.
HTTP Sampler
http://domain.com/rest/getValues?apiKey=sdfsdf&customerId=${custid}&timestampBegin=${begin}&timestampEnd=${end}

Resources