use a rest webservice response in another request using jmeter - json

suppose I have a webservice that generate random password and return json response, this password is used in the following request. is there anyway to do this in jmeter, i.e to extract the password from the first response and use it in the next request

We have Regualr Expression Extractor Or JSON Path Extractor in JMeter to extract the values from 1 response & use it in subsequent requests.

As Vinoth S said, JSON extractor is the way to go. You can download it from here. Document how to use it is here. Just put it in request from which you want to extract, type vairable_name that you will use in the next request as ${variable_name}, JSON Path is quite easy to set, probably, if the response is not to complicateg just the property name from JSON will be enough, or something like $.varName and you're ready to go.

Related

I am trying to get token but not able to extract it using JSON extractor

This is my JSON extractor
Debug sampler
Token I am getting in response
But the token is null
Your setup is wrong, the JSON attribute you're looking for is token, not the access_token therefore you need to amend your JSON Path expression to look like:
$.token
also it's hard to say looking at the image on which level the token lives, you might need to use deep scan operator instead like:
$..token
More information: API Testing With JMeter and the JSON Extractor

How to create multi-request based on last json response in JMeter?

I will get json response from last request, then I will parse the response and get a variable array, then create new request base on each element in that array one by one. I don't know how to implement it.
Use JSON Extractor and ForEach Controller combination. The idea is to have variables like:
var_1=foo
var_2=bar
var_3=baz
So you would be able to iterate them using foreach loop. See Using Regular Expressions in JMeter article to get the overall idea.
Steps to follow:
Add JSON Extractor (>= 3.0 version) Or JSON Path Extractor (< 3.0 version) plugin, to the HTTP Request sampler, as a child, in which JSON response is received.
Add the JSON Path Expressions to capture the specific values and store it in variable names, say capturedArray. refer JSON Path Syntax.
In later requests, i.e., HTTP Request Samplers, you can retrieve the array value by using the syntax ${capturedArray}

How to use JSON response from server to send POST request with parameters from JSON (jmeter)

I have some specific scenario for retrieving Access Token from API using jmeter.
I need to implement following test case and have no idea how to implement this (I am new in jmeter):
Send GET request to server.
Server will return following response: {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600}
After that I need to send POST request to server with parameter of "RequestToken" from step #2.
Thanks!
Answer of Dmitri T really helped me! Thanks a lot!
If your response {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600} is the full one you can add a Regular Expression Extractor Post Processor to GET request configured as follows:
Reference Name: anything meaningful, i.e. token
Regular Expression: {"RequestToken":"(.+?)","Expires":3600}
Template: $1$
After that you can refer to extracted value as ${token} or ${__V(token)} in POST request.
If you need to deal with more complex JSON structures I would recommend using JSON Path Extractor available via JMeter Plugin. It allows fetching data from JSON responses in more "intelligent" way as big JSON entities cannot be easily parsed via regular expressions.
In this case relevant JSON Path query will look like $.RequestToken.
See Using the XPath Extractor in JMeter guide for more details (scroll down to Parsing JSON).
Hope this helps.

Jmeter - Fetch the Session ID from the Response and pass it next request.Request & Responses are in JSON

Scenario :-
Im performing Load testing using API's
HTTP Request 1
I logged in using http://cabhound.com:1000/v2/driver/login and I got the below response
{"statusCode":200,"statusMessage":"Success","errorMessage":"","responseData":{"id":0,"userName":"PQeurentraps5S#tarento.com","firstName":"Partner","lastName":"Tarento","phoneNumber":"2641148625","email":"tamvrentrapnsr#tarento.com","password":"","addressOne":"","addressTwo":"","city":"","state":"","zipCode":"","loginCount":156,"welcome":"","smsOptIn":false,"promoCode":"","userNotification":"","errorMessage":"","message":"","sessionId":"6063tnerLt3013951671120oDse18492930#2","osType":"","osVersion":"","deviceType":"","deviceId":"","latitude":"","longitude":"","timeZone":"","appVersion":"","company":"Tarento","licenceNumber":"","vehicleType":"","vehicleFeature":null,"subscriptionType":"unlimited","driverWorkingCity":"Bangalore","vehicleNumber":"","locationUpdateTime":20,"rate":0,"reliable":0,"distance":0.0,"eta":0,"latitudeLongitude":"","status":"ON","payment":{"paymentType":"","cardNumber":"","cvnNumber":"","expDate":""},"vehicleTypeList":["Sedan","Limousine","SUV/Wagon","Minivan","Other"],"vehicleFeatureList":["Navigation System","Eco Friendly","Handicap accessible","Accepts credit cards"],"driverId":582,"currentLocation":null,"companyCode":"tarento","acceptanceRate":0,"like":0,"profileIndicator":0,"payWithCabHound":false,"smsSupport":false,"paymentInfo":false,"geoInfo":"","active":true}}
Please see the session id in the above response,which I want to use in next http request data
HTTP Request 2
http://cabhound.com:1000/v2/driver/dutyStatus
Below is the data which I need to post,here I want to use session id of HTTP Request 1
{"status":"ON","sessionId":"1311tnerLt9013956793297oDse462783#2","longitude":"77.686700","userName":"erpkrentrapJps#tarento.com","latitude":"12.934487"}
How to pass the session id of HTTP Request 1 (response) to HTTP Request 2 Post Data
Help me in this which I have strucked
I would recommend using JSON Path Extractor available through JMeter Plugin (you'll need Extras with Libs Set.
Regex are headache to develop, especially for JSON data which can be multiline. Beanshell has known performance issues, so using a plugin is the best option.
Relevant JSON Path query for your sessionId will look as:
$.responseData.sessionId
See Parsing JSON section of Using the XPath Extractor in JMeter guide for more details and XPath to JSON Path mapping
I can see 2 solutions for above problem,
Use Regular expression extractor to extract the value (I haven't used it with json response but I think it will work)
Use Beanshell preprocessor or postprocessor in which you can get response and find required sessionID using substr or json parsers or use simple java code. Extract the required value and use it in next request.

Using Rest assured to validate saved JSON response

I have a question regarding REST Assured. - https://code.google.com/p/rest-assured/wiki/Usage
I understand that I can use REST assured to make HTTP calls(.get .put etc.) and validate the response using when() etc. I would like to validate JSON responses that I have already saved in the database, instead of Calling the web service realtime and validating it's response.
Can I use REST-assured to Load a JSON response as a String and validate it?
Yes you can use Rest Assured's JsonPath project independently of Rest Assured (see getting started page). Once you have it in classpath you can do something like this:
JsonPath jsonPath = new JsonPath(<your json as string>);
String title = jsonPath.getString("x.y.title");