How do i Pass JSON Multiple parameters in JMeter with different users? - json

In my current scenario i need to login with multiple users into application and create articles using provided input formed in json which have more than 50 parameters.How can i do that need to prepare two csv files or what,pls suggest.

I would come up with:
A single JSON file containing placeholders for JMeter Functions and Variables which you will be using for parameterization like:
{
"firstName": "${firstName}",
"lastName": "${lastName}",
"phone": ${phone},
etc.
}
Then I would create a CSV file containing the parameterization information like:
firstName,lastName,phone
John,Doe,123456789
Jane,Doe,987654321
etc.
Configure JMeter to read the data from CSV using the CSV Data Set Config
Reference the file from point 1 in the "Body Data" section of the HTTP Request sampler using __eval() and __FileToString() functions combination:
${__eval(${__FileToString(data.json,,)})}

Related

Splitting set of JSON files using Azure Data Factory into multiple files

I am pulling data from an API at regular intervals (ic every 5 mins or more frequently).
Example of the returned info:
{
"timestamp":"2022-09-28T00:33:53Z",
"data":[
{
"id":"bdcb2ad8-9e19-4468-a4f3-b440de3a7b40",
"value":3,
"created": "2020-09-28T00:00:00Z"
},
{
"id":"7f8d07eb-433b-404c-a9b3-f1832bdd780f",
"value":4,
"created": "2020-09-28T00:00:00Z"
},
{
"id":"7f8d07eb-433b-404c-a9b3-f1832bdd780f",
"value":6,
"created": "2020-09-28T00:05:00Z"
}
]
}
So after a certain amount of time I would have a set of files in the landing zone:
2022-09-28T00:33:53Z.json
2022-09-28T00:43:44Z.json
etc...
I would like to use ADF to take those files and split them on a certain property.
So it would end up in a hierarchy like this:
/bdcb2ad8-9e19-4468-a4f3-b440de3a7b40/2022-09-28T00:33:53Z.json
/bdcb2ad8-9e19-4468-a4f3-b440de3a7b40/2022-09-28T00:43:44Z.json
/7f8d07eb-433b-404c-a9b3-f1832bdd780f/2022-09-28T00:33:53Z.json
/7f8d07eb-433b-404c-a9b3-f1832bdd780f/2022-09-28T00:43:44Z.json
where each file only has the data related to itself.
Any thoughts on how to pull this off?
Bonus: if for every run of the ADF I could union the files into a single one, that would be great but not absolutely necessary
Read the source file.
From the source file Data field will iterate with ForEach activity.
Parameters were provided for the sink dataset with FolderName and FileName.
Provided sink folder path and file path dynamically.
Values for the given parameters were provided in COPY ACTIVITY
Result with Expected files

Get complete json body from csv in Jmeter

I have a CSV file like this
"{""data"":{""student"":{""name"":""random name""}}}",
"{""data"":{""student"":{""name"":""random name2""}}}"
CSV image for better understanding:
Here I have two JSON strings.
I tried to send these as a JMeter variable as a POST ${body}. It actually takes the value from the CSV, but JMeter sends the value as a string rather than a JSON body. Is there any way to perse those data from CSV and send those as a POST JSON body?
For example, the POST body should be like this:
{
"data": {
"student": {
"name": "random name"
}
}
}
But now, it's like this
"{""data"":{""student"":{""name"":""random name""}}}"
I config the CSV data set in JMeter and send the variable this way:
Just for your info, I do not want to separate the data from the JSON one by one and put variables in the POST body for every JSON data separately. I want the full JSON body from the CSV.
JMeter sends what it finds in CSV file, remove extra quotation marks from the CSV file and JMeter will start sending the valid JSON.
If you cannot manipulate the data in the CSV file, i.e. it's coming from an external source, you can remove these extra quotation marks using JSR223 PreProcessor.
If you want just to send new line from the file with each subsequent request and the file is not very big take a look at __StringFromFile() function, it just returns the next line from the file each time it's being called.
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Data Factory Copy Data Source as Body of Sink Object

I've been trying to create an ADF pipeline to move data from one of our databases into an azure storage folder - but I can't seem to get the transform to work correctly.
I'm using a Copy Data task and have the source and sink set up as datasets and data is flowing from one to the other, it's just the format that's bugging me.
In our Database we have a single field that contains a JSON object, this needs to be mapped into the sink object but doesn't have a Column name, it is simply the base object.
So for example the source looks like this
and my output needs to look like this
[
{
"ID": 123,
"Field":"Hello World",
"AnotherField":"Foo"
},
{
"ID": 456,
"Field":"Don't Panic",
"AnotherField":"Bar"
}
]
However, the Copy Data task seems to only seems to accept direct Source -> Sink mapping, and also is treating the SQL Server field as VARCHAR (which I suppose it is). So as a result I'm getting this out the other side
[
{
"Json": "{\"ID\": 123,\"Field\":\"Hello World\",\"AnotherField\":\"Foo\"}"
},
{
"Json": "{\"ID\": 456,\"Field\":\"Don't Panic\",\"AnotherField\":\"Bar\"}"
}
]
I've tried using the internal #json() parse function on the source field but this causes errors in the pipeline. I also can't get the sink to just map directly as an object inside the output array.
I have a feeling I just shouldn't be using Copy Data, or that Copy Data doesn't support the level of transformation I'm trying to do. Can anybody set me on the right path?
Using a JSON dataset as a source in your data flow allows you to set five additional settings. These settings can be found under the JSON settings accordion in the Source Options tab. For Document Form setting, you can select one of Single document, Document per line and Array of documents types.
Select Document form as Array of documents.
Refer - https://learn.microsoft.com/en-us/azure/data-factory/format-json

How to use csv to provide different values for json assertion for different inputs in Jmeter?

I am relatively new to API Testing.
Currently I have a setup where I am having different request jsons and for each request json there is different repsonse json assertion configuration provided with the appropriate values in Jmeter.
Since my json structure will be same and only the input values will be different, I am thinking to generalize the input values using csv and keep only one request configuration.
But would I be able to provide different values(like jsonpath and expected value) to one response json assertion configuration using csv? Because the jsonpath and expected value both will depend upon the input provided and it can have major difference as per the case.
If yes, then how to do it please let me know.
Also if I can achieve my use case using other free API Testing Tool like Postman then also let me know.
You can normally parameterize any JMeter Test Element using CSV Data Set Config
For example you have the following response:
{ "name":"John" }
And the following CSV file:
$.name,John
$.name,Jane
Add CSV Data Set Config to your Test Plan and configure it like:
Add JSON Assertion as a child of the request which returns the above JSON and configure it like:
That's it, each virtual user and/or iteration will pick up the next line from the CSV file and the ${jsonPath} and ${name} placeholders will be replaced with their respective values:
as you can see, the first request passed because name matched John and the second failed because the assertion expected name to be Jane and got John

Using Jmeter, I need to add UUID extracted from JSON in CSV in same column (multiple values of UUID) So to pass in Delete Path

Using Jmeter, I need to add UUID extracted from JSON and add that in CSV in same column (multiple) to feed in Delete Request (REST). This is to test multiple delete calls which has unique UUID generated from POST call. Or is there any other way I can test multiple delete call after extracting from POST calls. Lets say 50 Post then 50 Delete calls.
I don't think you need to do anything as given threads reside in the same Thread Group you should be able to use the same variable for the Delete request.
JMeter Variables are local to a thread so different threads will have different variable values.
If you are still looking for a file-based solution be aware of fact that you can write an arbitrary JMeter Variable into a file using Groovy code like:
Add JSR223 PostProcessor after the JSON Extractor
Make sure you have groovy selected in the "Language" dropdown
Make sure you have Cache compiled script if available box ticked
Put the following code into "Script" area
def csvFile = new File('test.csv')
csvFile << vars.get('your_variable')
csvFile << System.getProperty('line.separator')
This way you will get any extracted UUID written into test.csv file in JMeter's "bin" folder, you can use it in the CSV Data Set Config for your Delete request.
More information:
Groovy Goodness: Working with Files
Apache Groovy - Why and How You Should Use It