How to transfer data among APIs - jmeter

We have tried everything could someone please help us for the solution
I am sending a Get Request and getting this response {"UserID":"123456","SecurityApp":"123456"}
I want to save "UserID" content to a variable and also "SecurityApp" content to a variable and then use it in multiple POST request content

You have to use Regular Expression Extractor component of JMETER...
You will get both the UserID and SecurityApp using Regx Extractor.
and you can use those variables in subsequent requests...

There is a test element designed for extraction of data from JSON structures - JSON Path Extractor. It's available via JMeter Plugins - a set of custom extensions which make working with JMeter (and especially reporting) much more easier.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for installation and usage instructions.
For particular your case detailed steps will be:
Download Extras with Libs Set bundle to your JMeter installation root and unpack it.
Restart JMeter if it is running - plugins are not being picked up dynamically
Add a JSON Path Extractor as a child of the request which produces that UserID/SecurityApp response
Configure it as follows:
Variable Name: anything meaningful (i.e. UserID)
JSON Path: $.UserID
Repeat step 4 but this time provide $.SecurityApp as JSONPath and SecurityApp as a Variable Name.
After Post Processor's execution you will be able to refer extracted values as ${UserID} and ${SecurityApp} wherever required in current Thread Group.

Related

Unable to pass Jmeter recording test when running the test in real website- one section get fail?

I want to do load test as well as performance test a website and I have recorded user step by step action through jmeter recording by proxy setting. And when I run this recorded test it gets passed all the sections except one section.
During recording steps, it gets filled all the required fields like POST, GET, PATH etc by default as well as like token, session id etc in the HTTP header manager. When user login again its get unique session id and token through Regular Expression Extractor. But my test gets failed when the user wants to accept a task it says unauthorized. I have attached screenshot.
This image showing all the steps user will do from login to logout.
Here steps 2.9 section gets fail.
Here its showing the response from the server.
Please let me know where am I doing wrong.
There are multiple possible issues with your test:
Location of the Regular Expression Extractor and other Post and Pre-Processors. According to JMeter Scoping Rules they are applied to all your Samplers so please double check if this is something you're looking for. If you want to apply the Post-Processor to a single sampler - you need to move it to be a child of the particular sampler
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider converting your Beanshell test elements into JSR223 ones
Since JMeter 3.0 there is JSON Extractor which you should be using instead of the plugins
In general HTTP status 401 means Unauthorized so double check that your test is doing what it is supposed to be doing using View Results Tree listener. You might also want to double check JMeter Variables values using Debug Sampler as it might be the case that the variables are being overwritten with something you don't expect due to the aforementioned Scoping Rules potential issue

Multi value assertion in jmeter

I am testin an api response.
The api response contains a parameter courier id .
Which appears multiple times in response, with differnt values.
I need to test if all the values in the response are as expected.
For single value testing i am using
Courier_id : value.
How to modify this to test all the occurances of this parameter in response.
I would recommend going for JSON Path Assertion available via JMeter Plugins project
This way you will be able to perform assertions basing on JSON Path queries.
JSON Path Assertion and Extractor can be installed using JMeter Plugins Manager

JMeter zip file download from server

I have a requirement to download zip file from server through JMeter to test the peroformance but for me the downloaded files are shown in x-filler, i need to have the zip file downladed.
Please help me here
Thanks in Advance
Simulating file download event using JMeter is as simple as sending HTTP GET request using HTTP Request sampler.
If you need to save the response somewhere for later reuse or analysis add Save Response to a file listener as a child of the request which performs the download. Check out Performance Testing: Upload and Download Scenarios with Apache JMeter article for comprehensive explanation.
Be aware that storing responses will cause huge disk IO overhead during the load test so I would recommend ticking Save response as MD5 hash box under "Advanced" tab of the HTTP Request sampler and use MD5Hex Assertion to compare the MD5 checksum of the response with some reference value.
To download any file, you need to extract it using Regular Expression Extractor.
Add the Regular Express Extractor to the request where you want to download and configure the fields as shown below. Use (?s)(^.*) as the expression to extract everything.
Add the Save Responses to a File sampler and configure the fields as shown below.
Execute the test plan. In the JMETER_HOME\bin\, you can see the zip file. Extract the zip file and validate.
The easiest way is to use your own code to download the file. The options are BeanShell Postprocessor or JSR223 Postprocesor.
I extracted file name from response header Content-Disposition, save it to varible, and the use variable for filename. Additional variable was defined on Test level, holding folder name where to save files.

How to fetch session id using reqular expression

Hi I want to fetch a session id from following response using reqular expression
<form id="fm1" action="/cas/login;jsessionid=08D3BEEBAAB30126106472355249AB49" method="post">
I want output as jsessionid=08D3BEEBAAB30126106472355249AB49
I have tried many way, but not working
Thanks.
You can do it via Regular Expression Extractor configured as follows:
Field to check: Body
Reference Name: anything meaningful, i.e. sessionId
Regular Expression: jsessionid=(\d\w+)
Template: $1$
try going through jmeter wiki, the latest one covers in a very good and generic way
http://jmeter.apache.org/usermanual/regular_expressions.html
Use following regular expression: jsessionid=(.+?)"
By the way, you can test regex against real response using RegExp Tester option of the View Results Tree listener.
By the way, there is an easier option to capture JSESSIONID value. In majority of cases it is a HTTP Cookie hence you can easily access it's value using HTTP Cookie Manager
Add the following line to user.properties file (it's located under /bin folder of your JMeter installation)
CookieManager.save.cookies=true
Restart JMeter
Add HTTP Cookie Manager to your Test Plan
Access captured cookie value as ${COOKIE_JSESSIONID} where required.
See Using the HTTP Cookie Manager in JMeter article for more detailed explanation of the importance of this configuration element.

Jmeter: Issue with Response Data (HTML) and Is my script Functional?

I am using Jmeter(2.3.2) to create script for one of my application with a scenario which has flow for 4 to 5 pages. I have recorded the script using HTTP Proxy Server. The scripts has been generated successfully under Thread Group >> Recording Controller.
After running the scripts (Threads- 1, Ramp Up period - 1, Loop Count - 1 ), below are the observations I noted in View Results Tree:
The Result Tree view shows all as Checked(Green) - OK
The Sample result for all screens shows Error Count as 0 - OK
But in the response tab when I try to view the results by using 'Render Html' response data - the response data shows the same response for all the requests.
I am getting the response data of the first request for all the other requests.
I am not sure, whether the Jmeter script generated is functional or not? What is the cause for getting the same response data for all the requests?
Please, can anyone let me know what may the issue?
I bet that the same page you're observing is a kind of login page or dashboard which is accessible by unauthenticated user.
First of all make sure that you have HTTP Cookie Manager added to your test plan. It represents browser cookies and deals with user sessions and cookie-based authentication.
If it doesn't resolve your issue the problem is bigger and you will need to do some extra stuff. Modern web applications use multiple mechanisms of current state of things storing and managing, security enhancements and so on. From JMeter's point of view it results in dynamic mandatory parameters. The process of these dynamic parameters extraction from previous request and adding them to next request is called "correlation". So you need to do the following:
Detect which parameters being sent by a recorded script are dynamic. The easiest way is to record the same scenario several times and inspect request bodies to see what is being static and what changes.
Once you figure out which parameters are "interesting" you need to locate them in the first response body/headers/etc.
As soon as you have identified what necessary parameters are and where they live you need to use one of JMeter's PostProcessors to extract required values from previous response and save them to JMeter Variables
Once you have a JMeter Variable it can be used wherever required.
Depending on response data type the most commonly used JMeter's Post Processors which provide correlation capabilities are:
Regular Expression Extractor - the most commonly used test element which covers >90% of needs.
XPath Extractor - better to use against XML data i.e. for testing SOAP Web Services.
CSS/JQuery Extractor - when you need to fetch something from complex HTML where Regular Expression Extractor is useless.
So for putting everything together loog for "jmeter correlation" in your favorite search engine or see ASP.NET Login Testing with JMeter guide.
First JMeter 2.3.2 is WAY TOO OLD (10 years old), upgrade to JMETER 2.11.
Second, Jmeter cannot guess that the response if KO if the returned code is 200, so you need to add Response Assertion that will check for some text you expect in the page.

Resources