Change the request body - insomnia

In Insomnia test suite, is it possible to add or update the request body?
For example, I have get/post request in a collection which takes a json as request body, I like to test the request by changing this json. By default in test suite I can select a request and the defined json (under collections) is used for testing, what if I want to change this json request?
An example code is
const response1 = await insomnia.send();
expect(response1.status).to.equal(200);
Is it possible to change what is posted in insomnia.send() within the test suite? As of now I have to go to the collection change this json but what if I want to test the same api end point with different jsons?
I am aware, I can test it under collection (Debug tab) by changing the JSON and directly testing there but I am trying to leverage the test suite to write a bunch of test against an end point. Insomnia uses Mochajs for testing, is there any sample of that used long with insomnia?
I cannot find any pointers in Insomnia documentation.

Related

load and performance test of the AWS API in jmeter using two post methods

I need to test the load and performance test of the API which is hosted in the AWS API gate way. Im using two post methods to get the final result. first post method will pass the below parameters in json format in the API.
{
propno:"xxxxx",
apikey:"xxxx-xxxx",
user:"xxx"
}
by executing this i will get a reference number and status of the execution
{
reference:"ABxxxxxxxxxna",
status:"ok"
}
Then will pass this reference no in another post method to get the desired result.
{
refno:"ABxxxxxxxxxna",
apikey:"xxxx-xxxx",
user:"xxx"
}
Now i want to perform the load test in Jmeter. Any help would be appreciated.
What is your question exactly?
In JMeter you can send a POST request using HTTP Request sampler, the relevant configuration would be something like:
the refno value can be fetched using JSON Extractor configured like:
next in the second HTTP Request use ${refno} reference to the JMeter Variable
You might also need to add a HTTP Header Manager and configure it to send the Content-Type header with the value of application/json
once done you can
Add more users in the Thread Group according to your NFR/SLA/common sense/whatever
Run your test in command-line non-GUI mode
Generate HTML Reporting Dashboard and analyze the results

Is there a way to set headers for GET requests in KDB?

I'm trying to make get requested with .Q.hg (HTTP get), but I need to edit the request headers to provide API keys. How can I do this?
You can try this function I wrote a few years back for a POC (similar reason - I needed to supply multiple headers). It's based on .Q.hmb which underpins .Q.hp/hg. Please note - it was never extensively tested & there are likely better alternatives out there, but it will perhaps work as a quick solution.
k)req:{[url;method;hd;bd]d:s,s:"\r\n";url:$[10=#url;url;1_$url];p:{$[#y;y;x]}/getenv`$_:\("HTTP";"NO"),\:"_PROXY";u:.Q.hap#url;t:~(~#*p)||/(*":"\:u 2)like/:{(("."=*x)#"*"),x}'","\:p 1;a:$[t;p:.Q.hap#*p;u]1;(4+*r ss d)_r:(`$":",,/($[t;p;u]0 2))($method)," ",$[t;url;u 3]," HTTP/1.1",s,(s/:("Connection: close";"Host: ",u 2),((0<#a)#,$[t;"Proxy-";""],"Authorization: Basic ",.Q.btoa a),($[#hd;(!hd),'": ",/:. hd;()])),($[#bd;(s,"Content-length: ",$#bd),d,bd;d])}
It takes 4 arguments:
Resource URL
HTTP method
Dictionary of headers
Message body as JSON object
Sending a request to a test server..
q).j.k req["https://httpbin.org/get";`GET;("Content-Type";"someOtherHeader")!(.h.ty`json;"blah");""] // no body so pass empty string
args | (`symbol$())!()
headers| `Content-Type`Host`Someotherheader`X-Amzn-Trace-Id!("application/jso..
url | "https://httpbin.org/get"

Default preset of headers in Postman

When manually testing requests in Postman, is there a way to define some set of default headers to be used for each request (without choosing manually Preset before sending each request)?
I.e. is there a way to define a default Preset to be used?
Additionaly when I follow some of the links in the response (by clicking on it) and send a request for this link, the headers from the original request are lost. Is there a way to preserve them automatically?
Thanks in advance
There is no direct way to do this but this can be done via Collection level Pre-request script. Steps-
Create a collection in the postman and put all requests in which you want the common headers.
Edit the postman collection.
Write this in your Pre-request Script section.
var Header = require('postman-collection').Header;
pm.request.headers.add(new Header("foo:foo"))
pm.request.headers.add(new Header("bar:bar"))
As of 7.0.9 - You should be able to now do this in your Pre-request Scripts.
You can use the following syntax:
pm.request.headers.add({key: 'header_name', value: 'header_value' })
pm.request.headers.upsert({key: 'header_name', value: 'header_value' })
pm.request.headers.remove('header_name')
Tips: Fork this collection to see how it works directly in Postman:
https://www.postman.com/postman/workspace/postman-answers/collection/9215231-ef055751-7385-45b4-a6f9-91bbd1c47fa5?ctx=documentation

Jmeter - Set custom text on request tab using JSR223 sampler

I am creating a script on groovy to be able to send http requests.
To call this script I'm using the JSR223 Sampler
The thing is that I would like to reproduce as much as possible the behaviour that a HTTP Sampler has, meaning that I want to perform the request and also to fill the sampler's info (Response data, Request and Response)
Although I'm able to obtain SampleResult and set Response data and Response, does not seem to exist a method to set our own request string:
https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
Following the docs, the closest method to do what I want is the setRequestHeaders().
If I call that method like this SampleResult.setRequestHeaders("My custom text") something like this appears on the request tab:
File C:\Users\UserName\groovy_file.groovy
Request Headers:
My custom text
Is there any way to print only the string My custom text, on the Request?
EDIT
Sampler must use a script file instead of the script field
The easiest way would be just overwriting the data using prev.samplerData() shorthand from the JSR223 PostProcessor
prev.samplerData = 'put the desired request data here'
where prev stands for the parent SampleResult class instance, check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on the JMeter API shorthands available for the JSR223 Test Elements.
If you don't want the PostProcessor you can still call the same function from your Groovy script like:
SamplerResult.setSamplerData('put the desired request data here')

Syntax to use parameters in Body section of HTTP Request Sampler in JMeter, using Rest API POST request with body and input from CSV file

I'm using JMeter to test a microservice and I need to use a parameter dynamically with a different value in each request. Also, the parameter is a part of a query that contains other constant values as well.
I defined user variables in the JMeter user.properties file (in JMeter bin folder):
JMeter -- bin/user.properties
# Parameters to use in JMeter
ES_HOST=127.0.0.1
ES_PORT=9200
ES_INDEX=segments
ES_TYPE=_doc
THREAD=5
CSVDATA_ROOT=C:/devtools/apache-jmeter-5.2.1/csv_data
Of course, I have User-Defined Variables:
And how my Test Plan is defined in JMeter
As you can see in the following screenshot of View Result Tree the parameter agentName I defined and shown in the HTTP Request (above) is working.
I want to define it in the body of the HTTP Request, to replace the hardcoded "John Doe" with a parameters that have a different value in each request.
"query":"SearchStartTime=2020-01-01 00:00:00.000TO2020-01-31 23:59:59.999&AgentName=John Doe"}
How can I do that?
I need a way to add a parameter to an existing string
I've already tried Using Apache JMeter to Test Elasticsearch (or any REST API) and In Jmeter, What would be syntax of parameters in Body Data section of HTTP Request Sampler, for Rest APIs and input should be generated dynamically also doesn't solve my problem.
Use same syntax as HTTP request - ${agentname} for getting variable value:
"query":"SearchStartTime=2020-01-01 00:00:00.000TO2020-01-31 23:59:59.999&AgentName=${agentname}"