How to load test GraphQL API with Jmeter - jmeter

I want to configure Jmeter to test the performance of following GraphQL API. I am unable to configure.
API End Point : https://graphqlzero.almansi.me/api
Query : query: {
user(id: 1) {
id
name
}
}``
Please help me with a solution.

It seems that you're trying to execute a POST request therefore you need to:
Add HTTP Request sampler to your test plan and configure it like:
Textual representation of the body just in case:
{
"query": "{user(id: 1) {id name}}"
}
Add HTTP Header Manager to send Content-Type header with the value of application/json
Demo:

If you have the call as a cURL command line, you can use menu:
Tools > Import from curl
Otherwise:
add Thread group
add a Header Manager inside it with Content-Type set to application/javascript
Add in it a Http Request, put in host the host name and in path the /api/

Related

java.lang.IllegalArgumentException with value {3D} in URL query

My Get Request has query value {3D} in the url when i make request using this it throws java.lang.IllegalArgumentException same request works fine in browser and postman
I tried to provide sample URL for debugging by there is no URl with it
You cannot have either { or } in the URL path section without encoding so the options are in:
Use __urlencode() function like:
${__urlencode({3D})}
Or put your query under "Parameters" tab of the HTTP Request and tick URL Encode? box
In general if the request works in browser or postman you can just record the request using JMeter's HTTP(S) Test Script Recorder
Instructions for browser
Instructions for postman
In query you need to encode the {} signs, send instead encoded value:
%7BD%7D
Or use urlencode function
${__urlencode({D})}

How to user variable form webdriver sampler in HTTP Header Manager

I am able to extract auth_key from session storage .
I want load an API with auth_key in HTTP Header Manager
How can this be done.
var foo = WDS.browser.executeScript("return window.sessionStorage.getItem('ngStorage-jwtToken');")
var obj = JSON.parse(foo);
vars.put("auth",obj.oauth_token)
WDS.log.info(vars.get('auth'))
And I want to use auth as global variable to access on all threads.
Replace this line:
vars.put("auth",obj.oauth_token)
with this one:
WDS.vars.put("auth",obj.oauth_token)
Add HTTP Header Manager as a child of the request which header you need to amend and configure it like:
See General Concepts section of the WebDriver Sampler user manual entry to learn what pre-defined variables are available for the scripting.
Sdd HTTP Header Manager in scope with name auth_key and value ${auth}.
${auth} will be updated with the value from webdriver sampler.

Jmeter file upload using PUT not working

I am trying to upload a file using the PUT method, which is not including the file in the request. I have followed the other example POST methods, but considering PUT does not allow multipart to be checked, that might be the issue.
I am also using:
* httpClient4
* jmeter 3.3
screenshot : https://www.evernote.com/shard/s126/sh/b4ebf947-c7e4-4e0a-9ebf-8e42a5f5d082/6813671cb2ab7419
Request data:
PUT http://myurl----here/app_path/test__16525587b4361f339ca33a9cdf0e9201d90e76dc__1676871c-71b8-488a-9750-29554a4be722
PUT data:
[no cookies]
Request Headers:
Connection: close
Content-Type: application/octet-stream
Content-Length: 0
Host: int-cloudstore-perf.svc.netspot.com.au
User-Agent: Apache-HttpClient/4.5.3 (Java/9.0.1)
Your test does't seem to be sending anything as your Put data should not be blank.
I would recommend to remove data from the Parameter Name section of the "Files Upload" tab of the HTTP Request sampler as PUT method is different and it doesn't assume submitting an HTML form and most probably your request will start working as expected (at least it will send data to the server)
Just in case check out Testing REST API File Uploads in JMeter article

NiFi ListenHTTP processor: how to specify "allow post"?

Just getting started with nifi.
Have an http processor of type "ListenHTTP" listening no port 9090
Need to allow http POST on http://localhost:9090/ end-point
I was unable to locate any "acceptable http verbs" settings within the Web UI for this processor, so my guess is - it needs to be specified in some sort of config file.
My question is: what file would that be, and what is the actual syntax to specify this?
I have seen some xml templates on line, but I'm not sure where to put one.
By default, if no alternative base name is specified, the ListenHTTP processor's endpoint is available at:
http://{hostname}:{port}/contentListener
Accordingly, your request should, for default settings, be:
curl --data "param1=value1&param2=value2" localhost:9090/contentListener
The full documentation on the processor is available at ListenHTTP or if that link breaks, via the Nifi Documentation page.
Alternatively, if you were looking to restrict your endpoint to specific verbs consider the combination of HandleHttpRequest and HandleHttpResponse
I believe by default it will accept all verbs. I configured ListenHttp on port 9090 with an empty "Base Path" property, and was able to use curl to POST data to it successfully. What kind of issues are you having?
The ListenHTTP processor...
... starts an HTTP Server and listens on a given base path to transform
incoming requests into FlowFiles. The default URI of the Service will
be http://{hostname}:{port}/contentListener. Only HEAD and POST
requests are supported. GET, PUT, and DELETE will result in an error
and the HTTP response status code 405.
-- Nifi Documentation, ListenHTTP 1.6.0
I have been able to POST to Nifi using PowerShell with Invoke-WebRequest, but needed to specify -ContentType:"application/x-www-form-urlencoded". This content type is set implicitly in the curl command in the answer from #apiri.
The example below works, and as an added bonus shows how you might include a header that will set an attribute on the resulting flowfile. Remember that you need to set the optional HTTP Headers to receive as Attributes (Regex) property in the processor configuration.
[PS] $HttpPost = #{
Uri = "http://{hostname}:{port}/contentListener"
Method = "POST"
ContentType = "application/x-www-form-urlencoded"
Headers = #{MyAttribute = "SomeValue"}
}
[PS] $Body = Get-Content <some_file> -Raw
[PS] Invoke-WebRequest #HttpPOST -Body:$Body
VERBOSE: POST http://{hostname}:{port}/contentListener with -1-byte payload
VERBOSE: received 0-byte response of content type text/plain
StatusCode : 200
StatusDescription : OK

How can I set "Content-Length" for Visual Studio web performance test request?

I have created a web performance test in VS 2015, and am trying to set request headers. When setting headers such as "Referer" or "User-Agent" everything seems to work fine. I just set the header by right-clicking the request and adding a new header, and when I run the test and inspect the request I can see that the new header has been added. However if I try to add a new header named "Content-Length" and then run the test, this header is missing from the request. I'm getting an http error which I assume is because VS doesn't use the "Content-Length" header:
HTTP Error 411. The request must be chunked or have a content length.
I ran into this problem as well. The consistent trend with these issues online seems to be when the content-length is 0. Otherwise VS seems to dynamically come up with the content-length header on it's own.
Explanation of Problem
Esentially, I don't think you can add it manually. VS wants to add this itself, so the real problem is why isn't VS adding this?
The problem comes from the request being simply a "Request" and not a "Web Service Request", the significant difference here being that the latter includes the "String Body" component. I'm assuming that VS does this because the content-length it recorded was 0. I recorded my workflow in Fiddler and got the same result. I would also assume that the reason adding the Content-Length header doesn't work is because this gets calculated by Visual Studio if the request has a body in the request.
The Workaround
Make the request a "Web Service Request" so that it includes the String Body component. In the test, right click and choose "Insert Web Service Request".
I got clued into this from the below post (which also includes an example for a coded UI test):
https://social.msdn.microsoft.com/Forums/en-US/da492346-760e-4971-a666-8897ae7b35e3/length-required-error?forum=vstswebtest
Plugin Option
I couldn't find a way to just convert my existing request into a Web Service Request, so I created a WebTestRequestPlugin that can be added to a request to dynamically add a body to the request.
Add the below to your project
Change the namespace to match your project's name
Build your solution.
Right click on the problematic request and click "Add Request Plugin" and then select this plugin.
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
namespace YourProjectName
{
[DisplayName("Add Request Body")]
[Description("If a request is intended to have a content-length of 0, the Web Test won't include an empty String Body and the Content-Length header won't " +
"be added during test execution. This may result in a 411 - Length required error. This plugin can be added to that request to add a body to the request" +
"during test execution.")]
public class AddBodyToRequestPlugin : WebTestRequestPlugin
{
public AddBodyToRequestPlugin()
{
}
public override void PreRequest(object sender, PreRequestEventArgs e)
{
// Add string body if it doesn't exist yet.
if ( e.Request.Body == null )
{
e.Request.Body = new StringHttpBody();
}
}
}
}

Resources