extract http request response and proceed to next http request by using while controller - jmeter

I want to use while controller to keep sending GET HTTP Request and only proceed to next POST HTTP Request when the GET response "model_name": "Model-Test-20220221-0001"
POST HTTP Request - paramter model_name = Model-Test-${variable}-${counter}
While Controller
GET HTTP Request. sample GET response at below
Json Extractor
POST HTTP Request only when While Controller found the exact model_name.
JSON Extractor:
Names of created variable: modelname
Json path expressions: I have tried this but failed
$..valid_model_list[?(#.model_name = ${Model-Test-${variable}-${counter}})]
This is sample HTTP Request response:
{
"message": "success",
"valid_model_list": [
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0001",
"status": "ok"
},
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0002",
"status": "ok"
}
}
]
}
}

We're "unsure" as well as we don't know what you're trying to achieve.
JSON Extractor can extract values from the response, it's not possible to use it to extract values from the request, moreover you should "know" what you're sending in the request and extracting values from the response is the essential part of the correlation process
If you're looking for a JSONPath expression extracting the model_name attribute value you're supposed to provide full JSON. There is a Deep Scan operator so you should be able to use something like:
$..model_name
but if there are more than 1 matches you might need to limit the output with Filter Operators
More information:
JsonPath Getting Started
API Testing With JMeter and the JSON Extractor

Related

Jmeter: Json Extractor: Response from first request to be used in next Request

I have a Http request for which i am getting data from CSV data file and i am getting a response body as {"abc":"123456123"}. I have added JSON extractor as child to this Http request. I am given variable name as abc and tried json path as both $..abc or $.abc and now i have added new Http request(2) in which i want to pass variable name from json extractor in request body(2). I have used same variable name in the http request body(2) but the variable name is not passing in the new request.
I gave all the options in json path in json extractor, i am expecting that for each response {"abc":"123456123"}(this value will change for each request) json extractor should get the response value and pass in the next request body.
When i am running the script, the value is not passed in request2.
Response of request 1 :- for single thread
{"abc":"123456123"}
Json Extractor:-
name of variable : abc
JSON path:- $.abc
Request 2:-
{
"a":{
"b":[
{
"mRID":"${abc}",
"abc":[
{
"a":[
{
"n":[
{
"na":[
{
"a":"",
"a":"AF",
"value":"add"
}
]
}
],
"cr":[
{
"name":"0071",
"nameType":"r#"
},
{
"name":89923,
"nameType":"NR#"
}
],
"CS":[
{
"dateTime":"${__timeShift(yyyy-MM-dd'T'hh:mm:ss)}",
"type":"CS",
"value":"x"
}
]
}
]
}
]
}
]
}
}
I cannot reproduce your issue using Dummy Sampler and the JSON Extractor configuration you described.
Try adding Debug Sampler after the uuu request and see if there is abc variable generated and what value does it have.
Also check jmeter.log file for any suspicious entries

Jmeter | if reponse has list it's getting null how to fix it?

I am trying to do POST data and it's getting 200. but if in response JSON data has list [] like
{
"resno":"5600123",
"inquiry": [
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
},
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
}
]
}
this then i recieved this.
{"resno":"5600123","inquiry":null}
It's working fine in Postman.
how can i fix?
Given you send the same requests you should have the same responses, double check your request payload and headers using View Results Tree listener or maybe even better an external sniffer tool like Fiddler or Burp
Once you identify and eliminate the differences - you should get the same behaviour.
Be aware that it's also possible to record the Postman's request using JMeter's HTTP(S) Test Script Recorder, if you configure Postman to use JMeter as the proxy - JMeter will intercept the request and produce the relevant HTTP Request sampler and HTTP Header Manager. See How to Convert Your Postman API Tests to JMeter for Scaling article for more information.

Jmeter - How to extract value from the request (not response) using RegEx

I have JSON request as following:
{
"type": "SIGNUP",
"data": {
"userAccountInfo": {
"email": "ta0620050706#gmail.com",
"password": "qweQwe123!"
},
"userAddressInfo": {
"country": "United States"
},
"userPersonalInfo": {
"firstName": "test",
"lastName": "test"
}
}
}
How can extract ta0620050706#gmail.com from the following request, considering the value of the email is always dinamic?
Any help is appreciated!
If you're talking about HTTP Request sampler and the above JSON is in the "Body Data" tab like:
You can extract the email by adding a JSR223 PreProcessor and using the following code there:
vars.put('email', new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue()).data.userAccountInfo.email)
It will extract the value you're looking for and store it into ${email} JMeter Variable
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

How to iterate through the contents of a Json object

On the JSR223 assertion in Jmeter, I need to validate only the inner part of the JSON returned.
I followed this thread to get an idea on the validation.
​How can I write JSON schema validation for JMeter run in TeamCity
Basically my Jmeter sampler returns the json as follows. On my schema, the validation should be for items, service and requestId. No validation should be performed for "payload".
{
"payload": [
{
"items": [
{
"code": "487482378",
"description": "Alpha Co",
"valid": true
},
{
"code": "92901128365",
"description": "Beta Co",
"valid": true
}
],
"service": "entities",
"requestId": "d190219"
}
]
}
This is my current code in the js223 sampler:
var schemaPath = '/path/entities-schema.json'
var rawSchema = new org.json.JSONObject(new org.json.JSONTokener(org.apache.commons.io.FileUtils.readFileToString(new java.io.File(schemaPath), 'UTF-8')))
var schema = org.everit.json.schema.loader.SchemaLoader.load(rawSchema)
schema.validate(new org.json.JSONObject(prev.getResponseDataAsString()))
You can remove the "unwanted" part of the response using JSR223 PostProcessor like:
def before = prev.getResponseDataAsString()
log.info('Before: ' + before)
def response = new groovy.json.JsonSlurper().parseText(before)
def after = new groovy.json.JsonBuilder(response.payload.items).toPrettyString()
log.info('After: ' + after)
prev.setResponseData(after, 'UTF-8')
Once done you can use your JSON Schema validation approach against the new content without elements you don't need.
References:
Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

MailChimp API 3.0 batch request returns 400 Invalid Resource error

I've been trying to use the batch endpoint of MailChimp API (version 3.0) to subscribe new users to a list, but can't make it work.
Here is the request:
POST /3.0/batches
{
"operations": [
{
"method" : "POST",
"path" : "lists/c852ce5c86/members",
"body": "{\"email_address\":\"email#domain.tld\", \"status\":\"subscribed\"}"
}
]
}
The request seems ok cause I get a 200 response:
{
"id": "49abca6ef3",
"status": "finished",
"total_operations": 1,
"finished_operations": 1,
"errored_operations": 1,
"submitted_at": "2015-09-21T18:11:16+00:00",
"completed_at": "2015-09-21T18:11:23+00:00",
"response_body_url": "https://mailchimp-api-batch.s3.amazonaws.com/49abca6ef3-response.tar.gz?..."
}
However, as you can see, the only operation in my batch is errored.
Here is the response_body_url for this operation:
[{
"status_code":400,
"operation_id":null,
"response":"{
\"type\":\"http://kb.mailchimp.com/api/error-docs/400-invalid-resource\",
\"title\":\"Invalid Resource\",
\"status\":400,
\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",
\"instance\":\"\",
\"errors\":[{
\"field\":\"\",
\"message\":\"Schema describes object, NULL found instead\"
}]
}"
}]
which is not very helpful :(
Note that if I directly hit POST lists/c852ce5c86/members with {"email_address":"email#domain.tld", "status":"subscribed"} payload, it's working properly.
That was actually a bug in the mailchimp API. After reaching them they quickly fixed it.

Resources