Getting  character in JMeter Response - jmeter

I am calling a login API from JMeter which return result in json format. For this API call I am getting expected result however the json response contains  character. In the request I have added, DataType:json and Content-Type: application/json;charset=utf-8.
Any advice.
Output Json Response

This is UTF-8 Byte Order Mark, your server responds this way so you might want to raise an issue against your application if this is not expected.
If your application functions as designed you can remove the BOM from the response using i.e. JSR223 PostProcessor and Groovy language, the relevant code would be something like:
def BOM = '\uFEFF'
def responseData = prev.getResponseDataAsString()
if (responseData.startsWith(BOM)) {
responseData = responseData.substring(1)
}
prev.setResponseData(responseData.getBytes('UTF-8'))
Check out Apache Groovy - Why and How You Should Use It for more information on Groovy scripting in JMeter

Related

I want to send the data that has been url encoding in Jmeter

I want to send a data that has been encryption.
So, I used JSR223 Sampler.
---skip---
def encrypted = Crypto.encrypt("AES/CBC/PKCS5Padding", "{"MY_SENTENCE"}", Crypto.generateSecretKey(), Crypto.generateIv())
vars.put("enc_data", encrypted);
Body Data in HTTP Request.
{ "data": "${enc_data}" }
In Results Tree
Request Body data was not url-encoding.
I want to send a data of url encoding, what should I do?
I don't know that.
I wrote Body Data in HTTP Request. So, I can't click the Parameters.
And I added Content encoding (UTF-8) it was not working too.
Either use __urlencode() function in the Body Data tab directly:
{ "data": "${__urlencode(${enc_data})}" }
JMeter Functions can be placed anywhere in the test plan and they're evaluated in the place where they're present so your ${enc_data} variable will be url-encoded in the runtime. See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.
or call URLEncoder.encode() function in your Groovy script directly:
vars.put("enc_data", URLEncoder.encode(encrypted,"UTF-8"));

Retrieve the particular entity from the request through a web request sampler

I am new to JMeter, I want to retrieve from the request sample (it is on websocket-request-response-sampler).
The request body:
ws://localhost:8080/connect
{
"uid": "JBM1",
"agent_name": "performance_test_1"
}
I want to retrieve the agent name. Tried with normal JSSR223 post processer, not working. Any help ?
If you're tried with "normal" JSR223 Post Processor you're supposed to share your "normal" code you used and the "normal" jmeter.log file contents
I believe "normal" code should normally look like:
new groovy.json.JsonSlurper().parseText(sampler.getPropertyAsString('requestData'))[0].get('agent_name')
Demo:
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
I have not done anything extra then #Dmitri rather few modifications, but please try it.
def requestBody = sampler.getPropertyAsString('requestData');
def jsonFormat = new groovy.json.JsonSlurper().parseText(requestBody)
def key = 'agent_name'
def agentName= jsonFormat."$key"
log.info("AgentName"+ agentName)
vars.put('AgentNameFurther',agentName)

How to write xpath assertion for the xml in Jmeter

I am using Jmeter to test the api transaction
Response:
<ProcessByAcctResult><Inquiry.IVR.OUT TraceId="1233"><ResponseCode>00</ResponseCode&gtgt;</Inquiry.IVR.OUT></ProcessByAcctResult>
My Response is given above..
I wanted to assert responseCode is 00 if not should make it fail on the performance test. How to write a xpath for this.. or else any other way also fine..
Currently i am storing the variable using Regex Extractor and REsponse Assertion to compare the value.. Any other better solution
What you provided is not a valid XML therefore you're only limited to Response Assertion configured like:
More information: Response Assertions in JMeter 3.2 - New and Improved
However if you're getting a real XML just not able to properly copy and paste it and your response actually looks like:
<ProcessByAcctResult>
<Inquiry.IVR.OUT TraceId="1233">
<ResponseCode>00</ResponseCode>
</Inquiry.IVR.OUT>
</ProcessByAcctResult>
Then you can use the following XPath Assertion configuration:

How can we Verify Json response using Beanshell in Jmeter?

I am getting Json as a response.
Instead of using multiple jsonPath_assertion I want to check it in single beanshell.
Each time I am getting Response with different values.
I would suggest using JSR223 Assertion and Groovy language instead.
Groovy has built-in JSON support so you will be able to use JsonSlurper class to parse the response like:
def json = new groovy.json.JsonSlurper.parseText(prev.getResponseDataAsString())
// do what you need here
Besides Groovy performs much better than Beanshell and it is recommended to use it for scripting in JMeter. See Groovy Is the New Black for more information.
You can use beanshell assertion.It will help you a lot.
prev.getResponseDataAsString() will return your json response as a string.
I hope you would be using Jsonpath online evaluator for evaluating json responses.
Suppose if my json online evaluator code looks like this $.items[2].CM_SEQNUMBER
In beanshell assertion i have used
JsonObject jsonobj = JsonObject.readFrom(jsonString);
JsonArray jsonarr = jsonobj.get("items").asArray();
String pickupToCheck=jsonarr.get(2).asObject().get("CM_SEQNUMBER").asString();
Similarly you can verify your JSON data without using multiple JSONPath Extractor using single beanshell assertion.

how to format JSON response in Jmeter?

How can I format json response in jmeter?
I don't want to tell which part of json answer
should be showed. I want to see my response not as
very long one line but as many lines formatted with new lines and
tabs/spaces.
I saw:
http://eclipsesource.com/blogs/2014/06/12/parsing-json-responses-with-jmeter/
Jmeter extracting fields/parsing JSON response
Thanks in advance!
I believe JSON Formatter PostProcessor is what you're looking for
If it is not suitable for you - take a look at JSR223 PostProcessor, it provides prev pre-defined variable (basically SampleResult instance) which gives read/write access to the parent sampler(s) response data so you will be able to do anything you want with the response using Groovy language

Resources