I Want to add different values using csv config in my following code - jmeter

In my below code i have to use multiple values in userEmail, userName, userMobile.
How can I do ti using csv config?
{"userDevicedId":"d0lfwViLwLQ:APA91bH4VSXS7VlthXhGQ4DPfb3otSUvwMnpmcK-mKyh7WN46xtDXWSYIOLB6Uw-nYr3zSBZOoiicpNuURQ2nR-a9vtwwSI8sehG-FbgYi4AaCdgurLG5C3Le4sYE0Lmp-piz_STLYnB","userEmail":"Tok#gmail.com","userMobileNo":"8989898995","userName":"Tik","userPasskey":"xmrVhb2MpmuzgLN941tGiLtdJnY3yvgMxlhXATEUa7SvsxclTiMLdJgPs7YTbNHF","userPassword":"Test123$$"}

Given your CSV file looks like:
someone#example.com,someone,1234567890
someoneelse#example.com,someoneelse,2345678901
etc.
Configure CSV Data Set config as follows:
Filename: full path to the CSV file
Variable Names: userEmail,userName,userMobile
Other config values - according to your scenario, see Using CSV DATA SET CONFIG guide for detailed explanation
Refer extracted values like ${userEmail}, ${userName}, etc. where required, i.e. if you want to send parametrised JSON it should look like:
{
"userDevicedId": "d0lfwViLwLQ:APA91bH4VSXS7VlthXhGQ4DPfb3otSUvwMnpmcK-mKyh7WN46xtDXWSYIOLB6Uw-nYr3zSBZOoiicpNuURQ2nR-a9vtwwSI8sehG-FbgYi4AaCdgurLG5C3Le4sYE0Lmp-piz_STLYnB",
"userEmail": "${userEmail}",
"userMobileNo": "${userMobile}",
"userName": "${userName}",
"userPasskey": "xmrVhb2MpmuzgLN941tGiLtdJnY3yvgMxlhXATEUa7SvsxclTiMLdJgPs7YTbNHF",
"userPassword": "Test123$$"
}
If you're using HTTP Request sampler, switch it to "Body Data" mode:
Remember that CSV Data Set config reads next line each iteration so make sure you provide enough loops on Thread Group level or via Loop Controller

Related

How to maintain json data for multiple testcases in robotframework

please suggest me how to maintain json POST data(for API testing) for multiple test cases in robotframework based on your past experience. Whether to maintain it in excel and separate json files?
If you have a "template" JSON and need to parameterize individual values you can use CSV Data Set Config for supplying these values, you request would be something like:
{
"parameter1": "${value1}",
"parameter2": "${value2}"
}
where these ${value1} and ${value2} will be populated from CSV data set config
If you need to send totally different JSON with each request it will make sense to put all the payload files into some folder and then:
Use Directory Listing Config to read the file paths into JMeter Variables
Use __FileToString() function for reading the file content into the HTTP Request body data
It's better to store POST data as separate JSON file. Here is how I would store:
- testdata
- json
- sample_file1.json
- sample_file2.json
There is advanced option if you don't like to store pre-defined JSON file for each test case but rather to generate one. You can use JSON Schema to generate JSON files, all you have to do is to create schema and generate JSON files based on that schema.

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

How to hit parameterized url in Apache 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

How to do parameterization for file name text of csv data set config in jmeter

I am passing the value for file name text filed in csv data set config as ${filename}, this variable contains entire path and fetching it form one more csv data set config which is present immediate to the thread group and the variable which I am passing to csv data set config that is inside the if controller here I couldn't able to pass that value to file name text filed, getting problem.
CSV Data Set Config cannot use JMeter Variable as the "Filename". However it is possible to use __property function there.
So your test plan should look as follows:
Read some value into a JMeter Variable i.e. foo via 1st CSV Data Set Config
Convert foo variable into foo property via __setProperty function
Use ${__property(foo,,)} as a "Filename" in 2nd CSV Data Set Config.
For more information on different JMeter's functions see How to Use JMeter Functions post series

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