In Jmeter, What would be syntax of parameters in Body Data section of HTTP Request Sampler, if I am using Rest APIs and taking input from CSV files? - json

I am trying to create 10 users at the same time in Jmeter, using REST APIs.
Test Data i.e. input is taken from CSV files (The details of users like user name, last name , mobile)
For this I have added one thread group,User Defined Variable,HTTP Header Manager, HTTP Request Sampler (which perform successful login into web application), JSON PATH EXTRACTOR ( to extract auth token, which will be used while adding user)
To Add User, I have used one "Loop Controller" - "HTTP Request Sampler" - HTTP Header Manager, CSV Data Set Config.
And to track result, View Results Tree and Aggregate Report.
Please tell me what would be the syntax of parameters which I am passing in "Body Data" section of HTTP Request sampler, so that it can read values from csv files.
Below is the syntax I am using now to add single user.
{
"phoneNo": "9998885551",
"lastName": "john25",
"email": "azp25#gmail.com",
"firstName": "ricky25",
"mobileNo": "9820420420"
}

If your CSV file looks like:
9998885551,john25,azp25#gmail.com,ricky25,9820420420
9998885552,john26,azp26#gmail.com,ricky26,9820420421
....
Configuration should be the following:
Filename: full path to your source .csv file
Variable Names: phone,lastname,email,firstname,mobile
Delimiter: ,
Populate other values according to your test scenario i.e. whether you want test to stop on .csv file end or re-spin or whatever.
And your HTTP Request should look like:
The main point is that variables defined in the CSV Data Set Config need to match the ones in the HTTP Request.
See Using CSV DATA SET CONFIG guide for detailed instructions.
I would also recommend adding the following entry to your HTTP Header Manager:
Name: Content-Type
Value: application/json
elsewise your request will be treated like plain text and may fail.
Also don't forget to disable View Results Tree listener for actual load test run as it consumes a lot of resources and may lead to out-of-memory errors on JMeter side.

Also,if your formparam\ Body data contains multiple parameters like this:
UserName=abc
password=abc123,
Instead of created two columns for userName and password, it can be given in single column like this:
UserName=abc&password=abc123
This way you can loop through multiple\different URL's which takes different numbers of bodydata
E.g.: If URL1 takes only username as body data and URL2 takes Username & password as body data the above will be an easy solution.

Related

JMETER - The string value from the CSV file is sent as array to the URL

I have the following API URL someexample/Create?Name=${Name} where through POST method in jmeter I send the value of Name from the CSV file.
In the response body the value of Name is [1,2,3,4] instead of User1.
Does anyone have an idea why the correct value defined in the CSV file is not being passed?
Thanks in advance.
It's impossible to tell what's wrong without seeing:
First 2 lines of your CSV file
Your CSV Data Set Config setup
If you have i.e. test.csv file which looks like:
User1
User2
User3
etc.
You can configure CSV Data Set Config as follows:
And refer the variable as ${Name} where required.
On each iteration each thread (virtual user) will pick up the next line from the file and the JMeter Variable placeholder will be substituted with data from the CSV in the runtime.
Also you can observe all JMeter Variables with their respective values using Debug Sampler and View Results Tree listener combination
More information: Using CSV DATA SET CONFIG

"Bad Request" message from Import Schema of Copy Activity in Azure Data Factory (ADF)

I have to migrate data from CRM Business Central into an Azure SQL database. The source data comes from REST API. I created a linked service related to it. Then I created a copy activity with the following:
The preview works. I get data in a JSON format. For the mapping tab, I tried to import the schema and set the field "value" as an array. I got the following result:
However, on the right side of the mapping, I can only see "#odata.context" proposed as a "sink mapping". I overwrote it by writing the right fields. When I run the pipeline with "debug mode", the pipeline is not triggered and I received a "Bad Request":
The error comes from the mapping. My question is: how does the "Import schema" work in case of JSON data? Do I have to import manually the schema?
Change the sink column #odata.context to other name by excluding the special characters.
I have reproed with a sample rest API and got the same error when I used the special characters (#, .) in the sink column ex :#data.id.
I have changed the sink column name ex: data_id to exclude special characters and the pipeline ran successfully.

Automating Requests Through Postman

I have ~10,000 records in a csv file that I need to run through postman and check the output it gives.
I was wondering (because I've been doing this manually) if there's a way to import the csv file into postman, and use the rows like variables and just 'scroll' through each result it gives out.
Cheers,
Daniel
This feature exists in Postman runner.
You have to make sure your CSV column's name(s) match the name(s) of your variable(s) in your collection.
You select your CSV file in the "data" part, just above the "start run", and when you run your collection, it will parse your file and replace the variable(s) with the value in the corresponding column and execute the request.
Then it will loop and get the next value and execute, and so on.
It just depends on the content of your CSV file and how you use it in your Postman request.
You shall have a look at those links :
https://www.getpostman.com/docs/postman/collection_runs/working_with_data_files
http://blog.getpostman.com/2014/10/28/using-csv-and-json-files-in-the-postman-collection-runner/
They will give you complete explanation about how it works.
Alex

how to run particular http request to multiple times in jmeter?

I've multiple http samples in Test Plan but i want to run only one request for multiple times based on csv data set config and remaining http requests will run once particular sample is complete all the iteration based on csv data set config.
In above image i've 5 http samples and i've csv data set for first request,once first request is run for entire csv data set test data then another samples should run,please provide solution how to perform this type of operation in jmeter.
you can use Loop Control and provide the number of hits you needed.
To go to Loop Control:
Right click on the Thread/ThreadGroup
Click on Add
select the Logic controller
Select the Loop Controller
According to the problem, there is a need to execute a particular request to execute in a loop. The loop could be organized in the following way.
-> Thread Group
-> Loop Controller
-->Particular Request
-> Other Request
The CSV Dataset could be found in Config Element and should contain a path to a particular file with data (e.g. accounts.csv).
Both elements could be located in
Loop controller: Add ->Logic Controller -> Loop Controller
CSV Data Set : Add -> Config Elements -> CSV Data Set Config.
The loop can run for the exact amount of records in a file if
Loop Count is equal to a number of strings in the accounts.csv
Forever, it could be stopped by Test Duration automatically or by Stop button.
The CSV Data Set config should have a path to a file with data.
If a file contains headers, then Variables will be assigned based on column names from first string, otherwise, it is necessary to provide variables names in configuration.
ANSWER: If you use 9 variables and all of them are set as header names in a file, then don't provide them in CSV Data Set Config. They will be created automatically, so you can use all 9 variables through names in your file.
If headers are not provided, set 9 all in a Variable Names field, using comma as separator.
Configure your CSV Data Set Config like:
Reference name: foo
Recycle on EOF: false
Stop thread on EOF: false
Put the CSV Data Set Config under the While Controller and put ${__javaScript("${foo}" != "<EOF>",)} into "Condition" input
Add If Controller under the While Controller and put "${foo}" != "<EOF>" into the "Condition" input
Put your first request as a child of the If Controller
Replace foo with your actual JMeter Variable reference name everywhere in the script.
This way JMeter will loop until there are entries in the CSV file and will proceed with the remaining requests when the end of CSV file will be reached.
See Reading all Values from the CSV and Continue chapter of the Using the While Controller in JMeter article for more detailed information on configuring JMeter for your scenario.
You can verify with only one variable and Rest variable you don't required in If and while controller.

Manipulating json string with Jmeter

Im new to Jmeter and web applications at all, I need some help with a json post.
I have an application with a POST request that sends a json string to save the data that was created/changed.
Here an example of the json code that is sent through the POST request
{"ID":0,"Description":"Test 1"}
With that the first user will create a new registry "Test 1", the second user will create another registry with the same description. I´d like to be able to set the ID and Description info as variables to manipulate them. When the post receive ID 0 is to make a new registry, when It receive an specific ID is to update that registry.
I´m trying to simulate some scenarios that user 1 create, user 2 update or user 1 create, user 2 create different. Things like that.
If your aim is to update the ID and the Description # run time,
Keep the ID and the Description in a CSV file. (something like below)
0, Test1
0, Test1
1, Test2
Use "CSV Data Set Config" (under Config element) to read the CSV file. update the file name and enter "ID,Description" in the variable names.
Update the JSON as
{"ID":${ID},"Description":"${Description}"}
This approach will read the data from CSV and update the JSOn # run time and send the request.
first thread / loop will take the first row and second thread will take the second row.
It should work..let me know if anything.