0

Collection has two requests.

  • Post - Create Account
  • Post - Create AccountProfile

Create AccountProfile adds an AccountProfile object to the Account.

There are 13 account-profile-types.

What I want to do is create 13 accounts, one for each account type.

Here is the Javascript in Tests for the second method.

Never mind the hard-coding for now. I'll fix that later.

var acctProfiles = [0,1,4,5,6,19,33,34,35,38,39,40]

for (var p in acctProfiles ) {
    // Create account with that profile
    console.log('creating account');
    postman.setNextRequest("Create Account");

    console.log(pm.collectionVariables.get("accountToken"));

    pm.collectionVariables.set("profileType", profiles[p]);

    console.log('creating profile');

    // Now call this request to create the profile
    postman.setNextRequest(); 

}

I ran this collection in the collection runner. It ran each request successfully, but only once.
It only used the last element in the array, 40. So, one account with one account-profile was created and no more.

Guy
  • 666
  • 1
  • 10
  • 34

1 Answers1

0

For loops in postman aren't working.

Each time you are using setNextRequest(); in Create AccountProfile it goes to the Create Account after that whole code from Create AccountProfile is execute not only the loop. Because of that, only the first execution from the loop will be executed.

You can achieve what you need in another way. You can store your array in a global variable and each time Create AccountProfile will be executed you can delete one item from it.

robmax
  • 332
  • 1
  • 6
  • 24
  • - Probably need to do a variant of this, since I don't want to have to continually re-enter the global variable. Thinking I'll store the global variable in a collection variable, and iteratively slice the collection variable. – Guy Jan 19 '20 at 06:01