Jmeter, How to get one of response result to assign to next request - jmeter

I have a response for request #1: 2 step codes that correspond with stepId as below.
In next request, I want to use only stepId = stepId that I assign from CSV file
**content**":[
{
"stepId":21,
"stepCode":"11",
"stepName":"11",
},
{
"stepId":17,
"stepCode":"??",
"stepName":"To be checked",
}
]

For example if you need to get stepCode value where stepId is 17 you can use JSON Extractor and the following JSON Path query:
$..[?(#.stepId == '17')].stepCode
Demo:
You can replace this 17 with a variable coming from the CSV Data Set Config like:
$..[?(#.stepId == '${your_variable_from_csv}')].stepCode
References:
Json Path Operators
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Related

How to parse a json with dynamic property name in OIC?

I need to consume and parse incoming json from a third party system in my code. I used RestTemplate to do it. So the response from the system looks like below.
{ "data": { "05AAAFW9419M11Q": { "gstin": "05AAAFW9419M11Q", "error_cd": "SWEB_9035", "message": "Invalid GSTIN / UID" } } }
Now the problem is the property name ("05AAAFW9419M11Q" in this case) in dynamic and in the next response it would be another string. In this case, how can I parse this json as this is not fixed in Oracle Integration Cloud? Response wrapper is not capturing the data apart from the one that is used for configuring the adapter which is fair enough as fieldname itself is changing.
Is there is any workaround for this?
You will have to go to PL/SQL and dynamic SQL, and if it's always the value of gstin entry, you can get the path of the key with
select '$.data.' ||
json_query(js_column, '$.data.*.gstin') into v_key path from table_with_json_column where ... conditions... ;
(assuming there is only 1 "data" per JSON payload) to later build a dynamic query based on json_table.

How to store json object in a variable using apache nifi?

The following flowfile is the response of an "InvokeHttp":
[
{"data1":"[{....},{...},{....}]","info":"data-from_site"},
{"data2":"[{....},{...},{....}]","info":"data-from_site"},
{"data3":"[{....},{...},{....}]","info":"data-from_site"}
]
I did a "SplitJson", i got each json record as a single flowfile
flowfile 1:
{"data1":"[{....},{...},{....}]","info":"data-from_site"}
flowfile 2:
{"data2":"[{....},{...},{....}]","info":"data-from_site"}
flowfile 3:
{"data3":"[{....},{...},{....}]","info":"data-from_site"}
I want to store each json record in each flowfile in a variable like that:
variable1 = "{"data1":"[{....},{...},{....}]","info":"data-from_site"}"
variable2 = "{"data2":"[{....},{...},{....}]","info":"data-from_site"}"
variable3 = "{"data3":"[{....},{...},{....}]","info":"data-from_site"}"
can someone show me how to store the json record in a variable !
If I understand correctly what you want to do (by "variable", do you mean what is called "attribute" in NiFi?), you can use the EvaluateJsonPath processor configured with:
flowfile-attribute as Destination
json as Return type

How to add parameters to a HttpRequest programatically in JMeter

I use JMeter in our product performance testing now.
I have a performace test scenario below:
Exract 1000 unique IDs from a request A.
Add the 1000 unique IDs to next request B as "form parameters". check the request B response time.
The request B is like:
Method: Post
URL: http://www.aaa.com/abc/def
Form parameters:
para1 : value1
para2 : value2
ID : ID1
ID : ID2
ID : ID3
......
ID : ID1000
I know this request isn't a Canonical usage of http request. but it is used in our product for years.
Now I get the 1000 unique IDs from request A with the help of "regular expression extractor",
My question is:
how to pass the variables to request B, and set the 1000 IDs as "form parameters" of request B?
Add JSR223 PreProcessor as a child of the HTTP Request sampler where you need to add 1000 parameters
Put the following code into "Script" area:
def data = new org.apache.jmeter.config.Arguments()
1.upto(vars.get('ID_matchNr') as int, index -> {
def parameter = new org.apache.jmeter.protocol.http.util.HTTPArgument('ID', vars.get('ID_' + index))
data.addArgument(parameter)
})
sampler.setArguments(data)
That's it, the JSR223 PreProcessor will read all the JMeter Variables which start with ID_1 and ending with ID_XXXX and add a corresponding parameter to the HTTP Request sampler
More information on Groovy scripting in JMeter context: Apache Groovy - Why and How You Should Use It

How to iterate the foreach loop in JMeter

I got the array response from the one API and I passed to the response to the other API.
For example:
Response from one API is {status:200,data:{name:"Manikyam", selected_products:[1,2,3,4,5]}
I need to iterate the selected_products from the response using foreach or other loop which is suitable of this.
Iterations like:
http://dummy.com/product/1
http://dummy.com/product/2
http://dummy.com/product/3
http://dummy.com/product/4
http://dummy.com/product/5
I tried some ways like using forEach but I haven't any luck.
The below answer assumes that your response is a valid JSON looking like:
{
"status": 200,
"data": {
"name": "Manikyam",
"selected_products": [ 1, 2, 3, 4, 5 ]
}
}
Add JSON Extractor as a child of the request which returns the above JSON and configure it as follows:
Names of created variables: anything meaningful, i.e. product
JSON Path Expressions: $.data.selected_products.*
Match No: -1
Add ForEach Controller and configure it as follows:
Input variable prefix: product
Output variable name: product
That's it, if you add a Sampler as a child of the ForEach Controller, the controller will iterate all the variables so you will be able to refer each and every as ${product} where required like http://dummy.com/product/${product}
Demo:

How to compare Variable with CSV file content in Jmeter

I have HTTP request whose response is below
{
"DATA": {
"G_1": {
"OR_ID": "100400",
"LEGAL_ENTITY": "TEST",
"BUSINESS_UNIT": "TEST BU"
},
"G_2": {
"OR_ID": "100500",
"LEGAL_ENTITY": "Test1 ",
"BUSINESS_UNIT": "Test1 "
},
"G_2": {
"OR_ID": "100100",
"LEGAL_ENTITY": "TEST3 ",
"BUSINESS_UNIT": "Test3"
}
}
I need to get OR_ID from the above response, which I am able to do it using Regular exp extractor.
There is Input CSV file which has multiple rows. For the CSV file, i need to check the OR_ID exists or not in column 2, if exists then I have to take columns 5 and 7 and pass it to my next post request in the body. In CSV the same OR_ID repeated, so i need repeat post request for all the repeated values of OR_ID in csv. CSV file has no header.
441919244,100010,QUTRN,TEST Inc.,100100,TEST,VCG and A, INC,USD,3409.0900,O,ICO-VCG-0140,2019-10-31,52 945,USD,USD,359409.0900,359409.0900,359409.0900,Processed,93901372,File,2019111NG52.csv,
441919028,100400,QUQED,TEST MEDICAL EDUCATION INC.,100020,QUINC,TEST INC.,USD,12.340,O,ICO-INC-8718,2019-10-31,52 729,USD,USD,12.3400,12.3400,12.3400,Processed,93901372,,File,20191113NG52.csv,
Can you please help.
Assuming that you can extract the OR_ID from the JSON response following solution could be useful.
In the CSV Data Set Config Element or Random CSV Data Set Config plugin read the CSV file assign the variable names to the respective columns
variable names = C1,OR_ID,C3,C4,C5,C6,C7,C8,C9
Add a While Controller as a parent to the CSV Data Set config elements and the HTTP Request where you want to send data from the CSV file.
${__jexl3("${OR_ID}"!="EOF")}
This will check EOF in the column 2 of the CSV file. Hence please add
,EOF,,
as the last line of the CSV file.
Add IF controller to the HTTP Request with following condition
${__jexl3("${OR_ID}"=="${OR_ID_J}")}
OR_ID_J is the OR_ID picked from the JASON response.
Use ${C5} and ${C7} in the places where you want to insert the data from the CSV file.
Reset the OR_ID to "" using a JSSR223 Sampler with following
vars.put("OR_ID", "");
Sample Test Plan is available in GitHub

Resources