jeudi 2 mai 2019

How to Write a conditional statement in postman based on a value in an array

Within each element in an array, there may or may not be a value that I need to grab. If the value is not in one element, I want to go to the next element to look for it. I'd like to know how to write the statement to do that in my Postman test. I already know how to get the values when they exist, but I want to go through each element until I find what I'm looking for to put in the variable.

I've googled how to write the code, but I'm new to this and I'm having trouble.

var jsonData = JSON.parse(responseBody); postman.setGlobalVariable("Date", jsonData.array[0].field[1]);

if (postman.setGlobalVariable("Date", jsonData.array[0].field[1]) === ??? else (postman.setGlobalVariable("Date", jsonData.array[1].field[1]);)

Aucun commentaire:

Enregistrer un commentaire