How to do addition in mapper using snaplogic? - etl

I want to do the addition of two input using mapper and send the data dynamically from the Postman in the form of JSON. So, want to add that data coming from the Postman.

I assume you will have a simple pipeline with only one mapper. Something as follows.
Say you take two variables a and b as input from the JSON like as follows.
{
"a": 2,
"b": 5
}
Then you can have an expression like $a + $b and map it to another output variable like $c. Please refer to the following screenshot.
You can then create a triggered task for this pipeline and fire from Postman with the above JSON as the body. Please refer to the following screenshot.

Related

Passing whole body as a variable to a POST request

I'm trying to create a simple stress test using JMeter. I have mostly GET requests and a couple POST requests. My main goal is to make this test as reusable as possible. I want to implement it in a way that the user would have to provide a CSV file with the following headers:
method;path;postBody
The values would look something like:
GET;/path/to/resource;''
POST;/path/to/resource;'{"key":"value","key":"value","key":"value"}'
Now POST (PUT, PATCH etc ..) bodies differ from one request to another. Providing ${postBody} to Body Data tab does not work "${postBody}" as well.
Is there a way to achieve this? Command line solutions are more than welcome as well.
EDIT: To clarify, I'm using the UI interface. When I input ${postBody} in the Body Data tab the UI complains. When switching from the Body Data tab to another one I get the following prompt:
Remove "'" around the request and it should work.
Regarding the warning you get, it is not an error, it is just that in JMeter those 2 tabs are exclusive:
Parameters tabs is for input of parameters in the form as name=value
Body data is for your kind of requirement
So can you test my hypothesis which is to remove the quote around the request in CSV file ?
If it still fails, please show the logs.
You can remain in Body Data tab,
Add after pathPost your optional query parameters for GET request:
${pathPost}?${getPramaters}
Don't worry about the ? it's just seperate path from parameters
Also consider changing variable name to path, more suitable because it can be POST.
In JSON , seperate between values while in CSV default is also ,
I suggest you can your CSV delimiter, In CSV Data Set Config Choose different Delimiter as ; and add your data in CSV accordingly (remove extra ' characters):
POST;/path/to/resource;{"key":"value","key":"value","key":"value"}
Notice: Allow quoted data keep default value False

JMeter - how to randomize number of parameters in request

I am new to JMeter.
In my GET request I want to have random number of parameters, so sometimes I want to have:
a = value1
a = value2
a = value3
and sometimes I want to have
a = value1
a = value2
etc.
Can I achieve it in JMeter in another way than making separate request modules?
You can specify parameters dynamically in the Path field, using a variable:
The variable should be created / formatted before HTTP request is sent. For example here I am using counter and BeanShell pre-processor to create a proper set of parameters:
So if I run this with 3 iterations, I will get:
GET http://stackoverflow.com/x?a=value0
GET http://stackoverflow.com/x?a=value0&a=value1
GET http://stackoverflow.com/x?a=value0&a=value1&a=value2
etc. Of course the logic of creating params should be based on your needs, this is merely an example. The reusable part of that example is saving params in a string, and then saving them into variable:
String myDynamicParameters = "";
// your logic here
vars.put("myDynamicParameters", myDynamicParameters);
If you want to generate variable directly inside your GET parameters, the fastest way is to use inline snippets.
something like:
GET http://xx.com/${__Random(1,99999)}
You can do it via i.e. Beanshell PreProcessor like:
sampler.addArgument("name", "value");
See:
HTTPSasmplerBase.addArgument() method JavaDoc
How to Use BeanShell: JMeter's Favorite Built-in Component for comprehensive information on using JMeter and Java APIs in your test.

Passing parameters to JMeter

I can successfully pass parameters through Jmeter as long as I embed them in the path like so:
But when I try to add them using the GUI, it doesn't work:
I have tried combinations of encode/unecode, as well as adding "?" to the path, but the result is the same - the server replies that the required parameter is missing. Any ideas?
This is a post request so pass this name value into Body data (click on body data tab) in json format
{
"Taskid": "9000"
}
or
{
"Taskid": 9000
}
if the type of 9000 is string then choose 1st option other wise 2nd, better to try with both options to check which one is working
Other approach:
try to change the method to get with same parameters as passed in snapshot2 (attached by you) but it might be possible this request does not supports get method then in that situation you have to post it only by passing in the Path field (as shown by you in snapshot 1) or in body data tab

How can I log the value of a variable sent in an HTTP Request sent from JMeter, if the value was first read in from a csv file

I would like to read the exact value of a variable I use to pass through an HTTP Request. I first read in many values of variables using the CSV Data Set Config. For the username, it is in the form of an email address. So, I have a variable called "email" in the Data Set Config. In the actual HTTP Request, for "name", I call it "username". For the "Value" field for this same "username", I added a time() function to it like this so I would end up creating unique users in my tests:
${email}${__time()
When I view the "Request" in a View Results Tree, I can see my parameter is listed correctly:
username=email1%40email.com1390854377360
I do not care if this is correct in real world terms. I already know that is not a valid email. That is ok for now.
What I want to know is how can I log that email that I just created on the fly? I would like to not have to pull in the whole request every time also and then use some type of Regular Expression extractor. It just seems like there should be an easy way to do this.
I think there are 2 ways,
Beanshell Pre/Post processors : you can write custom code in which you can log all your variables in some custom log file
Simple data writer : you can configure it and check save url,save field names,save response data field checkboxes that will give you complete data but in that later postprocessing on result file is required to get all usernames (email in your case).
first approach is easier and allows you create your own logging format(easy to retrieve and use somewhere else).
second approach is somewhat tedious and requires post processing.

Jmeter Parametrization

I'm very new to Jmeter. I need help with the input data file for jmeter.
Here is my situation.
My test data file structure is like this:
Test Case Name = XXXXXX11
RequestData = AAAAAAAAAA11
Expected Result = BBBBBBBBB11
Test Case Name = XXXXXX22
RequestData = AAAAAAAAAA22
Expected Result = BBBBBBBBB22
and so on ....
Now, I have to send the http request and verify the expected using Jmeter (Maven & Continuous Integration).
How can I parse the given file and verify the expected result?
I have tried the following:
__StringFromFile - but i don't know how to look for the line which has Request data or Expected result;
userParameter - but not sure how to pass values on runtime.
Could any of you please help me?
Do you have single test-case per file (i.e. single appearance of "Test Case Name",...,etc. in file)?
If so then you can possibly try to use custom Variables From CSV File plugin from Jmeter Plugins project.
My suggestion would be to convert your file to csv (with any delimiter you like). The first row becomes your heading, and each additional row becomes your data you want to pass in or validate. For example:
Test Case Name|Request Data|Expected Result
XXXXXX11|AAAAAAAAAA11|BBBBBBBBB11
XXXXXX22|AAAAAAAAAA22|BBBBBBBBB22
You can load this data in to your test plan using the CSV Data Set Config. Once you do, you'll be able to loop through each row of data if you set your Thread Group to Loop Forever. Then all you need to do in the test case is refer to your variables from the csv file like so:
${Test Case Name}.
Thank you so much guys!
I just wrote a bean shell script to parse the CSV file and stored all the request & response in the array and then created a for each loop around my http sampler. That met my requirement.
Thread Group
Beanshell preprocessr (To parse my CSV and to store it in an array)
For each loop (loops thru the array)
http sample
response assertion
Results

Resources