How to disable response parsing in Karate? - json

I'm using Karate 0.9.5. and am testing an endpoint that returns a 125MB json response (I know, shouldn't do that over json -- but am stuck for now). How can I disable Karate from parsing the response json and just treat it as plain text? The response takes milliseconds to come over the wire, but Karate just hangs trying to parse the response. I don't need to validate the response, just check for 200 OK.
Thanks.

You can't. I suggest you write a Java util (should be just 5-10 lines of code) to do a GET or whatever to this end-point and call it from Karate and save to something like target/temp.json or discard the response.
Refer to Java interop: https://github.com/intuit/karate#calling-java
If you use karate-apache then the Apache HTTP Client will be in the classpath. So you can refer to the docs: https://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e49
Also look at the end of this test for an alternative example of making a GET / POST in Java: ProxyServerTest.java

Related

Jmeter is not handling huge JSON payload

I'm trying to execute the Jmeter script POST call with some 55 thousands of line JSON payload, with this request I see the error as 500 in the Jmeter tool and also seen JSON parser error in the log-entries.
I think Jmeter is not handing with these huge request payload and not parse the correct JSON data to server.
NOTE: With the same payload I am able to execute the API via POSTMAN.
Please suggest how to handle huge payload in the Jmeter.
Thanks,
It might be a copy-paste issue, I would recommend using __FileToString() function directly in the HTTP Request sampler body like:
${__FileToString(/path/to/your/file.json,,)}
A better idea would be going for HTTP Raw Request sampler which has nice feature of streaming the file directly to the server without loading it in memory first

use a rest webservice response in another request using jmeter

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.

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");