Graphql with Jmeter - jmeter

I am trying to use jmeter to Automate graphql API testing. I have done the manual testing with postman. However, since some one suggested i am trying to automate with jmeter. unfortunately i am new to API testing itself and having great difficulties.
As i understand Graphql method only deals with POST, but in my Jmeter it is throwing an error, but when i change it to GET, i get 200 ok response.
Also in the body data i am directly entered the graphQL query is this correct.
In the return response data i don get any information related to my query.
I have added header manager with
Content-type = "Application/json"
Accept-encoding
Authorization
Accept
Connection
My graphql query is
query{cmCases(filters: {caseId:"case-6"})
{
items {
id
}
}
}
In the response i am just receiving meta data.

Looking into HTTP Methods, Headers, and Body chapter of the GraphQL documentation GraphQL supports both GET and POST methods so you can choose whatever you want or whatever you need
Looking into HTTP Headers documentation chapter header values are case-sensitive so you need to change Application/json to application/json in the HTTP Header Manager
Given you can successfully execute request in Postman you should be able to record this request by JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy

Starting with upcoming JMeter 5.3.1 or 5.4 you’ll be able to use the GraphQL Http Request.
Until it is released you can try a nightly build:
https://ci.apache.org/projects/jmeter/nightlies/
See:
https://github.com/apache/jmeter/pull/627

Related

Post Request getting failed due to webkitformboundary in JMeter

We have a recorded script using Blaze Meter(HTTPS call) and run in JMeter, One POST request getting failed and shows "500 Internal Server error". In Post request, JSON passed in form of "form-Data" as parameter. When endpoint executed we observed Webkitformbounday in HTTP header, Please give some solution for
HTTPs Request
HTTP Header Manager
POST Request Body
enter image description here
It looks like the recording solution you're using isn't very suitable for building proper HTTP POST request, I would suggest the following amendments:
Untick Use multipart/form-data box in the HTTP Request sampler
Remove issueDetail parameter name and put it to the end of "path"
Change Content-Type header value to application/json
Authorization header value might need to be correlated if the token life span is short
More information: Testing SOAP/REST Web Services Using JMeter

Is there any tool to debug the rest calls made by GraphQL Playground?

I'm not able to figure out why the REST API call works just fine in Postman but not in the GraphQL Playground. If I could see the actual REST call being made by GraphQL, would be helpful to debug the issue.
Firecamp's GraphQL client lets you test the GraphQL as an API call or as a Query way.
Here is the dedicated GraphQL client
Here is REST like GraphQL client
Note: Make sure that you double-check the method and headers while using REST-like GraphQL client. IN most cases method would be post and header should contains Content-Type: application-json / application/graphql
The GraphQL playground allows to send GraphQL queries/mutations to your GraphQL server. You can see the requests that are send using the network tab of a browser dev tools.
For example, if a server is in running at the following address http://localhost:4000/graphql, sending a query/mutation, a XHR request will be sent to it. In the Request Payload of the Headers section there is the query/mutation itself.
In the Response section you can see the returned response.
You can start having a look at the returned response of your query/mutation. Perhaps there is something wrong in the related resolve function in GraphQL.

"Post" method test result error in JMeter API testing

I tried to run a POST method for API testing in JMeter, I have sent the parameters as needed, but still it shows cannot post.
What should I do to make it work?
user add post request
response message
If you are testing an API my expectation is that you need to send either JSON or XML payload using "Body Data" tab of the HTTP Request sampler.
You will also need HTTP Header Manager to send the relevant Content-Type header
References:
Building a SOAP WebService Test Plan
REST API Testing - How to Do it Right
Another way of building a web service test plan is executing the request(s) according to your test scenario using a 3rd-party tool like Postman or SoapUI and recording them via JMeter's HTTP(S) Test Script Recorder.
In the post request, you need to provide server name or IP address and port number respectively. If it still doesn't work, try changing the path by adding /api then /user/data. it works in some cases.
Hope this works out!

How to pass the http request auto generated _token value (value generated under http request, not in response) to next http request in jmeter

I have a http request that auto generates '_token' value with the request(this value generated under http request only, not in the response of this request) and this '_token' value needs to be passed to the next http request header as 'authorization'. I know we can use JSON/RegEx post processor if it is in Response of the first http request. However how it be be correlated if the dynamic value is in http request.
Please suggest how can we achieve this in jmeter.
Most likely you are trying to load test an application which uses OAuth and depending on OAuth version and your application setup there could be different options. If the token is permanent - you can just put it into HTTP Header Manager, however if the token expires more or less frequently - you will need to implement OAuth flow using JMeter (in some cases you will need some extras like scripting, kick off browser to open a redirect URL or use OAuth client libraries). Check out How to Run Performance Tests on OAuth Secured Apps with JMeter article for details.
I would suggest contacting your application developers to learn about OAuth version, settings, required client id/secret, etc.

Response data section is blank in J-meter

In case of POST method I am not getting any response under Response Data section, while I did not receive any error in my test plan.
This happens only for Post and Get method and for rest of the others it is working.
Given your Test Plan name is "My First API Test Plan" my expectation is that you need to pass data a little bit differently.
Upgrade JMeter to latest version which is 2.13. It has new functionality, performance improvements, bug fixes, etc.
Remove everything from "Parameters"
Switch to "Body Data" tab
Insert your JSON payload there
Make sure that your HTTP Header Manager is configured to send Content-Type header with the value of application/json
More details and tips in Testing SOAP/REST Web Services Using JMeter guide.

Resources