Is there any way to store array/list as variable/parameter in constructing an API in Postman? - api

I'm trying to parameterize a url in Postman and loop over that list to call multiple APIs one after another and append the JSON bodies.
For example:
if the url is GET https://location/store/{{user_id}}/date
and
user_id = ['1','3','5','2','6','8']
then how do I store user_idas a variable such that request can loop over each user_idin the url and generate an appended JSON body?

You can use data files. Store the user id values into a csv or JSON file and call that file in to your collection runner. The headers of the csv files can be used as variables names. please see the details of this approach in the below link
https://learning.postman.com/docs/postman/collection-runs/working-with-data-files/

Related

How can I validate Postman API response contains the String mentioned CSV file

When running a Postman requests through Collection runner by passing the values contain in a CSV file for the input parameters, how can I validate each response contain the String text mentioned in the expected value column in this CSV file. I also want to write each response to the Actual result column in this CSV file.
For example after executing the 1st request in the above pic using the Postman collection runner I want to validate the response contains 'Sydney' as a text value and give the result as 'PASS' or 'FAIL' as well as write the actual response to the Actual result column of the above file. This should continue till the last row of the CSV file.
You can access the data in the CSV using the data dictionary, for example data.Scenario.
Checkout this article, chapter "Data variables in pre-request and test scripts".
I don't think it is possible to write data back to the CSV file.

I want to pass the header value in methods

Scenario : I need to verify the logs response on server on the basis of Tracking-Id.
I had passed the tracking-id using 'header.js' file, here i define metod which get the unique UUID for every request and passed in header.
Now I need that header value to passed in some method to get logs only for specific Tracking-Id
Is there any way to achieve this in karate?
Yes, you can use karate.set('someVarName', uuidValue) in JS and then back in the feature you will be able to: * print someVarName.
EDIT: please see this commit for an example: link

How to retrieve an array of values from Java API in Karate?

I'm reading WSDL path and XML Request from excel file. I need to use these two data in my feature file. Reading action has been done on Java side but I don't know how to pass these into Karate - feature file.
I'm aware of single value passing from Java API to Karate like this.
* xmlstring xmlVar = response
* def APIHelperClass = Java.type('com.org.utilities.APIHelperClass')
* def result = APIHelperClass.getResponseFromFeatureFile(xmlVar,'getMembersDetailsResponse.xml')
Suggest me how to receive multiple values / array from JavaAPI into Karate.
Thanks
Please refer to this example: cats-java.feature and the corresponding Java class: JavaDemo.java.
So if you return data as a Java List it will be a JSON array. And a Map becomes a JSON object. This is explained in the documentation.
In your case if you return a HashMap with 2 keys e.g. wsdlPath and xmlRequest you should be easily able to use it in Karate.

Karate Automation: Is there any way we can set the Scenario name dynamically from a json file [duplicate]

This question already has answers here:
Can we parameterize the request file name to the Read method in Karate?
(2 answers)
Closed 1 year ago.
I am using a JSON file which act as a test case document for my API testing. The JSON contain Test Case ID, Test case Description, Header and Request body details, which should be the driving factor of Automation
Currently i am looping a feature over this json file to set different header and body validations. However it will be helpful if i can set the Scenario name from JSON file while its iterating
Something like
serverpost.feature
Feature:re-usable feature to publish data
Scenario: TC_NAME # TC_NAME is avaliable in the JSON data passed to this feature. However, CURRENTLY ITS NOT TAKING THIS DATA FROM JSON FILE.
Given path TC_ID # TC ID is taken from JSON
Given url 'http://myappurl.com:8080/mytestapp/Servers/Data/uploadServer/'
And request { some: '#(BODY)' } # Request Body Details is taken from JSON
Please suggest
In my honest opinion, you are asking for a very un-necessary feature. Please refer to the demo examples, look for it in the documentation.
Specifically, look at this one: dynamic-params.feature. There are multiple ways to create / use a data table. Instead of trying to maintain 2 files - think of Karate as being both - your data table AND the test execution. There is no need to complicate things further.
If you really really want to re-use some JSON lying around, it is up to you but you won't be able to update the scenario name, sorry. What I suggest is just use the print statement to dump the name to the log and it will appear in the HTML report (refer to the doc). Note that when calling a feature in a loop using a JSON array, the call argument is ALREADY included the report, so you may not need to do anything.
Just an observation - your questions seem to be very basic, do you mind reading the doc and the examples a bit more thoroughly, thanks.

Jmeter - read parameters from csv and write back updated parameters

I'm using Jmeter for testing. I need to use some keys in order to perform login, and then change the keys.
I understood that the best way to do it is to create csv file that contains two variables.
I understand how I can read the parameters (using 'CSV Data Set Config'), but I still don't know how to extract specific parameters from result (new keys) and save them in file instead the old ones.
You can use Regular Expression Extractor to extract the values from the response. This site will give you an idea how it works.
It is NOT a good idea to write in the same file which is read by CSV dataset config. Instead, you can use Beanshell post processor to create a CSV file & write as you want.
import org.apache.jmeter.services.FileServer;
f = new FileOutputStream("/your/file/path/filename.csv", true);
p = new PrintStream(f);
p.println("content,to be,written,in,csv,file");
p.close();
f.close();