Which controller to use in Jmeter? - jmeter

I want to create a controller that should run a till the condition fails. How it can be implemented in Jmeter.
The controller should contain a HTTP Request with a post body which is dynamic the request should continue till the condition fails,but i dont know where the should i apply that condition.
{
"access": {
"identifier": "9876f",
"Reproduce": "Right",
"possible": {
"id": "u7ur038",
"value": "Move"
}
}
}
If the response "Reproduce" contain "Right"then it should run again HTTP Request for new body and If the response "Reproduce" contain "Wrong"then it should stop executing.

You can use a While Controller which will contain your request.
Condition of While Controller will be:
${__jexl3("${response}" != "Wrong")}
Add as child of your HTTP Request a JSON Extractor:
Names of created variables: response
JSON Path Expressions: $..Reproduce
Match No.: 1
To reset variable for next thread loop iteration, add before While Controller a Flow Control Action and put inside it a preprocessor called User Parameters .
Click « Add Variable » and set :
Name: response
User_1: Right

Related

How to debug JMeter the error JsonToken EndArray is not valid

Before hand will be some images as I don't know how to explain them better.
I have an HTTP Request POST that has the parameters below:
{"ShiftId":${Param_S02_ShiftId},"Date":null,"StartTime":"${Param_S02_Pick_Date}T00:00:00.000Z","EndTime":"${Param_S02_Pick_Date}T23:00:00.000Z","RouteTemplateId":${Param_S02_RouteTemplateId},"VehicleId":${Param_S02_VehicleId},"SelectedEmployees":[{"RouteTemplateRoleId":${Param_S02_RoleId_1_driver},"EmployeeId":${Param_S02_1_driver}},{"RouteTemplateRoleId":${Param_S02_RoleId_2_driver},"EmployeeId":${Param_S02_2_driver}],"TeamBoardId":${Param_S02_Teamboard}}
As you can see this is the same API sent by the browser
The problem is that I am getting this error message that I could not find the solution aroud.
{"message": "JsonToken EndArray is not valid for closing JsonType Object. Path 'SelectedEmployees1', line 1, position 237.","type":"Newtonsoft.Json.JsonReaderException","stackTrace":" at Newtonsoft.Json.JsonReader.ValidateEnd(JsonToken endToken)\r\n at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)\r\n at Newtonsoft.Json.JsonTextReader.Read()\r\n at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)\r\n at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)\r\n at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)\r\n at ApiService.EntityObjectServiceController2.ParseSaveRequestAsync() in C:\\a\\1\\s\\API\\src\\Framework\\ApiService\\EntityObjectServiceController.NETStandard.cs:line 151\r\n at ApiService.EntityObjectServiceController2.Create() in C:\a\1\s\API\src\Framework\ApiService\EntityObjectServiceController.NETStandard.cs:line 123\r\n at lambda_method3708(Closure , Object )\r\n at g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"}
Do I need to add something in the Header?
Maybe is something with this part of the call where I have 0 and 1
You're sending an invalid JSON, your SelectedEmployees array is missing closing bracked ], my expectation is that you need to amend your payload to something like:
{
"ShiftId": ${Param_S02_ShiftId},
"Date": null,
"StartTime": "${Param_S02_Pick_Date}T00:00:00.000Z",
"EndTime": "${Param_S02_Pick_Date}T23:00:00.000Z",
"RouteTemplateId": ${Param_S02_RouteTemplateId},
"VehicleId": ${Param_S02_VehicleId},
"SelectedEmployees": [
{
"RouteTemplateRoleId": ${Param_S02_RoleId_1_driver},
"EmployeeId": ${Param_S02_1_driver}
},
{
"RouteTemplateRoleId": ${Param_S02_RoleId_2_driver},
"EmployeeId": ${Param_S02_2_driver}
}
],
"TeamBoardId": ${Param_S02_Teamboard}
}
once you start sending syntactically correct JSON at least this error will go away, you can test it against i.e. online JSON validator
Going forward given you're capable of successfully execute the request using your browser you can just record it using JMeter's HTTP(S) Test Script Recorder or JMeter Chrome Extension

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

Use result from jdbc request for the next request

I am using JDBC to query on azure sql in JMeter. I was able to successfully get the response. see below
otp
100940
In the Result variable name the value is OTP
My next step in Http request POST method, see below
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}
as you can see otp is parameterized.
But in actual request see below;
POST data:
{
"id": 506,
"otp": "[{otp=100940}]",
"requestId": "123456"
}
how can I concatenate so that I only get the actual otp value without the [{otp=}]
You can add Regular Expression Extractor to extract number from OTP variable
Choose Apply To: JMeter Variable and write OTP and use regular expression as:
otp=(\d+)
And use Template $1$ and Match No. 1
JMeter Variable Name to use - extraction is to be applied to the contents of the named variable
If your response is this otp 100940, use below Regular Expression to extract it:
Now, you can use anywhere OTP value using ${OTP} variable
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}

How to correlate drop down list

I have a response like below-
"distributionChannelList":[
{
"id":1,
"description":"Agency1"
},
{
"id":5,
"description":"Agency2"
},
{
"id":4,
"description":"Agency3"
},
{
"id":3,
"description":"Agency4"
}
],
"marketingTypeList":[
{
"id":1,
"description":"Type1".......
There are so many 'id' and 'description' values in my response. Agency1, Agency2.. are drop downs in my application.
So I want Jmeter to pick a different agency every time and pass in subsequent requests.
How to achieve this?
Use json extractor or reg Ex to fetch all the description with Match No. as 0 for random. Pass the Json created variable to the next request like ${varDescription}. On every run, random value will be fetched and provided to the next request.
Below snapshot is an example for regex but prefer json in your case. For fetching with json use $..description as json path expression. Repeat the same for others if required.
Hope this helps.
Update:-
Please check the below config. It will extractor 2 values in sync. But, ${cnt} should be same value. I have used counter just for demo. You can use random function to generate value between 1 to 4 and pass that variable ${rnd};${rnd}.

JMeter Modify the GET response to use in PUT

I have two requests, the first one is GET, second is PUT. I should receive the response data from GET request, modify it a little bit and send with PUT request. So far I managed to do all, except modifying the response data.
For GET request I use Regular Expression Extractor as Preprocessor:
And currently I send the PUT request without modifying the data:
JSON structure:
{
"property1" : 1,
"property2" : "2",
"innerPropery" : {
"innerProperty1" : "value1",
"innerProperty2" : "value2",
"innerProperty3" : "value3"
}
}
I should change the innerProperty2.
Thanks!
You can do it without Regular Expression Extractor interim step.
Add JSR223 PostProcessor as a child of the getForm request
Choose groovy in the "Language" drop-down
Put the following code into "Script" area:
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
def response = prev.getResponseDataAsString()
def json = new JsonSlurper().parseText(response)
def builder = new JsonBuilder(json)
builder.content.property2 = '2.1'
vars.put("response", builder.toPrettyString())
In saveForm request use ${response} as the request body
References:
Parsing and Producing JSON
Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For!
I have managed to do this via BeanShell PostProcessor. First I have added a new BeanShell PostProcessor: click right button on getFrom, Add -> Post Processors -> BeanShell PostProcessor. After that I opened the reated BeanSChell and have written the following code in Script field:
responseString = vars.get("response");
log.info("Received response: " + responseString);
responseString = responseString.replace("\"prop1\" : \"value2\"", "\"prop1\" : \"value2.1\"");
log.info("Response to send: " + responseString);
vars.put("modifiedResponse", responseString);
In Parameters field I have written:
response
Finally, I changed for PUT request the body from
${response}
to
${modifiedResponse}

Resources