How to define email address with Jmeter user defined variables? - jmeter

Problem: In email address # replaced by %40.
http header manager:
user defined variables:
http request:
and result tree:
I have researched about this, and they say that, if http method is POST, then it should encoded automatically. But It does not encoded automatically. Any advice, how can I resolve this?
Note: Jmeter version : 3.1 and I am trying to test a rest service.

Please try sending data in Body data instead of sending it in parameters.

Change "Implementation" of your HTTP Request sampler to Java
If you need to change it for more than one sampler - it makes sense to define the setting using HTTP Request Defaults.

I found the answer. #PoorvajaDeshmukh's answer suggest me. Like following (correct defination of body data);
I also tried #DmitriT's suggestion, but I did not work. Thanks for advices...

Related

JMeter - Error when using __FileToString to set GraphQL request body

(this is a dummy example with SWAPI)
I'm trying to set my body based on what is in a file and it fails saying the JSON is invalid. But when I set the request body manually the same content the request works.
In the results tree view I can see that the only difference is that the manual request is "encoded", it has /n instead of visual newlines.
Here's the request that fails (body coming from file):
Here's the request that works (body manually set):
does anyone know a way to force this "encoding" when retrieving the query string from a file?
It looks like a limitation or bug of the GraphQL HTTP Request sampler, you might want to raise it via JMeter Bugzilla
In the meantime you can consider manually changing line breaks to \n using __strReplace() function, something like:
${__strReplace(${__FileToString(${fileName},,)},\r\n,\\n,)}
should do the trick for you.
You can install __strReplace() funciton as a part of Custom JMeter Functions bundle using JMeter Plugins Manager
More information: How to Use the Custom JMeter Functions Plugin
I've opened a bug for Apache and they acknowledged this behavior but it doesn't seem like something they'll fix soon.
I came up with a solutions that is close to what #Dmitri T suggested but without using any Plugins
I've created a JSR223 PreProcessor (Language: Groovy) that will replace the special characters that might break the request's JSON. So far the things that I've seen in GraphQL that might break it are new lines and double quotes.
def content = new File(vars.get('fileName')).text;
vars.put('queryContent', content.replaceAll(/(\r\n|\r|\n)/, /\\n/).replaceAll(/"/, /\\"/))

Jmeter getHeaderManager() command adding too many headers to the request

I have a Jmeter test which accepts auth Token header and added to the http request using the below command
sampler.getHeaderManager().add(new Header("Authorization","Bearer " + vars.get("BEARER")));
Its working fine for first few requests and then failing with below error
HTTP Error 400. The size of the request headers is too long
When I checked the header, it was actually added around 100+ headers for Auth Token [:O]. Please see details below. Could some one help me on this.
I suspect, that you call HeaderManager#add over and over again. The method add adds a header. While what you really want to do, is to replace a header. Sadly there is no method on the HeaderManager to do so.
But you can emulate it. First remove all headers named Authorization from the header manager and after that re-add the header with the new value. The code in Groovy would look like this:
import org.apache.jmeter.protocol.http.control.Header
sampler.headerManager.removeHeaderNamed('Authorization')
sampler.headerManager.add(new Header('Authorization', 'Bearer ' + vars.get('BEARER')))
Most probably your JSR223 Preprocessor is placed in incorrect location.
JSR223 PreProcessor obeys JMeter Scoping Rules therefore if you put it at the same level as multiple Samplers it will be executed before each Sampler in its scope.
So you need to make the JSR223 PreProcessor a child of the Sampler which header you want to modify and it should resolve your problem.
By the way, you don't need any scripting, headers can be added using HTTP Header Manager.

How to extract data from AMQP request in JMeter

I have used AMQP Publisher to publish the message in RabbitMQ then I use AMQP Consumer as listener. In the View Results Tree the messages from the queue in shown in the request tab of AMQP Consumer. My question is how to extract data from that request. I tried following the Bean Shell Post Processor but it seems it will only work on Http request. I tried to use JSR223 Post Processor and XPath extractor but it doesn't work as well. Any help?
I wanted to extract the documentId from the request. Here is the Request pattern.
I have already tried following links:
Extracting value from jmeter post request
how to extract value from request in Jmeter
How to extract the values from request input xml in jmeter
The statement that you tried something without sharing the code doesn't make sense
Posting JSON data or code as image is not the best idea
Any reason to extract data from the request? Normally people know everything about the request hence don't require to extract anything from it. Even if they do - they should normally able to store the request data into a JMeter Variable and apply the relevant Post-Processor to it.
Whatever, just in case here is the solution:
Add JSR223 PostProcessor (if you really want to do this using the Post-Processor) as a child of the request
Put the following code into "Script" area:
vars.put('foo', com.jayway.jsonpath.JsonPath.read(sampler.getArguments().getArgument(0).value,'$..documentId')[0])
That's it, you should be able to access the extracted value as ${foo} where required.
References:
JsonPath: Getting Started
Apache Groovy - Why and How You Should Use It

How to make json-rpc calls?

I've looked through previous questions about this but there was no definite answer so hoping someone can help me here.
I want to make a JSON RPC call using a Jmeter sampler but I'm not sure which one to use.
The request takes the following shape:
https://servicename.bla.com.service.dosomething({pass in JSON params})
If this is what you are talking about:
http://www.simple-is-better.org/rpc/#differences-between-1-0-and-2-0
You can use a regular HTTP sampler with Raw Post Body provided your service uses POST Method (which is what the example shows).
You can add an Http Header Manager to set Content Type

Jmeter for pages having dynamic token

I am recording a set of pages using JMeter. Some of the pages have dynamically generated token stored in hidden field.
I retrieve this token using xpath extractor, query is
//input[#name='__RequestVerificationToken']/#value, store it in variable and use this variable for next request.
I don't know why this request is getting failed. I have checked the request value in View Results Tree. In raw tab the value is exactly the same as that of hidden field and on http tab "==" is missing at the end.
As mentioned by Andrey Bolatov, there is a visualization issue in Request HTTP Tab which has now been fixed (you can test using nightly build.
This does not explain you issue.
To debug, add a Debug Sampler to see what has been extracted.
You issue may come from the fact that you didn't encode the parameter, read:
Send Parameters With the Request
Looks like a bug in JMeter. I reported it here - https://issues.apache.org/bugzilla/show_bug.cgi?id=54055

Resources