Questions tagged [postman-testcase]

169 questions
8
votes
1 answer

Postman scripting: how to decode token

I'm using postman with scripting. First, I perform a request to retrieve a oauth token. Then, inside the 'Test' tab, I'm using postman scripting to use the received token to set a global (postman) variable. Additionally, I would like to decode the…
4
votes
2 answers

Postman test to find a keyword in a response array

I am creating a test in postman to check for a keyword "pregnancy" in each "name" field in the JSON. If each 'name' field in the JSON contains the keyword then pass the test, else fail. Find the script below that I have tried using var jsonData =…
3
votes
1 answer

In postman, how can i run a new test based on whether another test has passed or failed?

I have two tests test A and test B. I want B to run only if A has passed. How can i do that in postman? pm.test("Status code is 200", function() { pm.response.to.have.status(200); }); pm.test("Check if fruits found with this search criteria",…
3
votes
1 answer

Postman test is always passing even though it fails

While running postman Tests, Test case seems to be always passing The response body is provided below. I am trying to fetch id when the name is "Erin" and validate that id is 800. Small piece of code that i wrote is below the response body written…
aak
  • 53
  • 5
3
votes
1 answer

How to Iterate through each JSON key-value pair in Postman

I'm writing tests in POSTMAN against a POST API request by sending JSON body data of the following format: "data": { "name": "Amber Joseph", "dob": "1988-10-13", "addressLine1": "Ap #770-9459 Quis Av.", "state": "WA", …
Muzna Zafar
  • 45
  • 1
  • 5
3
votes
2 answers

How to get the status of test(i.e. pass or fail or error) in Postman?

Here is my test case in postman pm.test("verify the JSON object keys for machines - ", function() { if (Object.keys(data).length === 0) { pm.expect(Object.keys(data).length).to.eq(0); } } Now if status of this test is PASS then I…
Dev
  • 2,296
  • 15
  • 30
3
votes
1 answer

How to set and get JSON.parse(request.data) in global variable in postman?

Can anyone let me know how to set and get the 'request.data' into a global variable as I am intended to access the request body of a post request in a subsequent get request later? I tried the below, but this is not…
Avai
  • 41
  • 3
3
votes
1 answer

Postman conditional tests if json body array is empty = skip tests

I want to integrate Postman/ Newman API tests into CICD, so the test results should always be passed (or skipped). Therefor I want to use conditional tests, dependent on the data of the response. I tried the method described on GitHub, but the…
Zeno
  • 33
  • 1
  • 3
3
votes
0 answers

postman password validation test with recaptcha response

Using postman I'm trying to test the password that inserted in the request by the user and check if its valid(6-14 characters and no spaces).I run post method test via postman with username and password in the body (RAW) and get a response with 403…
3
votes
3 answers

Postman : How to assert all array elements exist in other array?

I'm asserting for elements in array1 does exist in array2 or not, below are the array samples, var array1 = [ { "name": "appe", "loc": "war", "order": 5, "neck": "NO", "end": false …
Dev
  • 2,296
  • 15
  • 30
3
votes
1 answer

Is there a way to retrieve the redirected url from a Postman response?

I'm trying to submit a form in Postman which then redirects to another url. The redirected url query string contains some information that I want to use in my next call. Is this even possible and if yes, how? I haven't been able to find anything in…
user2865020
  • 58
  • 1
  • 5
2
votes
1 answer

Run multiple images/files with iteration data variable using Postman Runner or Newman

Scenario I have a POST request API which accepts Image or File. As shown below: I can select an image from the Request body as a form-data but, here I can select one image at a time. But I want to upload multiple images or files as a form-data…
2
votes
1 answer

POSTMAN - how to check response body for a value > 0

I'm fairly new to postman and am struggling to find an answer to the below I have a query that returns data such as the below: { "dailyProcessing":{ "2020-10-01":{ "Database":{ "list0":0, "list1":0, …
KDSP
  • 23
  • 5
2
votes
0 answers

Add automatic tests to Postman Collection when exporting Swagger Collection

I'll go step-by-step. I have a node js program that refers to a swagger specification json file and converts it into a Postman importable collection file (also in JSON format). I am doing this using "swagger2-postman-generator" npm library. For a…
user1710861
  • 384
  • 5
  • 8
2
votes
1 answer

Postman test to check the number of decimal places

I would like to test that the number of decimal places returned by a field in the response is equal to 5. Not sure if using regex is the best solution but this is what I have so far which does not seem to work: pm.test("Check number of decimal place…
kz500
  • 21
  • 2
1
2 3
11 12