How to maintain json data for multiple testcases in robotframework - jmeter

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.

Related

How to pick json playload from external file in jmeter?

How to pick json playload from external file in jmeter?
I Want to login with multiple users for that I need to add Json request. I need to pick json parameter/Json request from external file. Please let me know the process so that i can pick json parameter from external file.
Json request for example
{"username":"honey#est.com","password":"Phone#123","provider":"","access_token":""}
If you want to read a single line from a file - go for CSV Data Set Config or __StringFromFile() function
If you want to read entire file - go for __FileToString() function
If you have a folder with multiple JSON files and would like to iterate all of them - check out Directory Listing Config
It's also possible to read a file using JMeter's HTTP Request sampler
this way you will be able to use Post-Processors to extract partial data if needed.

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:

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

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

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