# Arg.executions in \`test\` event

**URL:** <https://community.postman.com/t/arg-executions-in-test-event/15764>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [September 10, 2020, 4:47pm UTC](https://community.postman.com/t/arg-executions-in-test-event/15764 "2020-09-10T16:47:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aurelien.lair](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@aurelien.lair](https://community.postman.com/u/aurelien.lair)\
**Post date:** [September 10, 2020, 4:47pm UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/1 "2020-09-10T16:47:20Z")

</div>

Hi guys,

could you please explain what `args.executions` is referring too on the `test` event callback?  
I printed it and tried to find the documentation of its meaning specifically for that event I can’t figure it out.

```auto
}).on('test', function (error, args) {
    console.log(args.executions.length);
}

```

is always returning 3 elements. What are these 3 elements?  
I need to understand it because on [this](https://community.postman.com/t/in-newman-used-as-package-how-to-retrieve-an-environment-variable-during-the-iteration/13838/13) thread @udit suggested to use `args.executions[0]` to retrieve the environment variables. I just want to understand why `args.executions[0]` and not `args.executions[1]` or `args.executions[2]` for instance?

Below an example:

```auto
[
  {
    event: PostmanEvent { listen: 'test', script: [PostmanScript] },
    script: PostmanScript {
      id: '0b5f0147-b5ac-4489-8751-bafc6aac36f4',
      type: 'text/javascript',
      exec: [Array],
      _lastExecutionId: '40c6e1b9-478c-4a97-95ed-e92fcb64a20a'
    },
    result: {
      id: '40c6e1b9-478c-4a97-95ed-e92fcb64a20a',
      target: 'test',
      legacy: [Object],
      cursor: [Object],
      data: {},
      cookies: [],
      _variables: [PostmanVariableScope],
      environment: [PostmanVariableScope],
      collectionVariables: [PostmanVariableScope],
      globals: [PostmanVariableScope],
      request: [PostmanRequest],
      return: {},
      response: [PostmanResponse]
    }
  },
  {
    event: PostmanEvent { listen: 'test', script: [PostmanScript] },
    script: PostmanScript {
      id: '4325ec73-bdf0-4ada-af76-d86a003f6d61',
      type: 'text/javascript',
      exec: [Array],
      _lastExecutionId: '332c1c2c-913a-442e-9e0f-f893fb548087'
    },
    result: {
      id: '332c1c2c-913a-442e-9e0f-f893fb548087',
      target: 'test',
      legacy: [Object],
      cursor: [Object],
      data: {},
      cookies: [],
      _variables: [PostmanVariableScope],
      environment: [PostmanVariableScope],
      collectionVariables: [PostmanVariableScope],
      globals: [PostmanVariableScope],
      request: [PostmanRequest],
      return: {},
      response: [PostmanResponse]
    }
  },
  {
    event: PostmanEvent { listen: 'test', script: [PostmanScript] },
    script: PostmanScript {
      id: '9db33696-7fe1-4ca3-8010-dd927ebb2fbe',
      type: 'text/javascript',
      exec: [Array],
      _lastExecutionId: 'c1bf9766-b91d-4898-825b-0d38661f4a54'
    },
    result: {
      id: 'c1bf9766-b91d-4898-825b-0d38661f4a54',
      target: 'test',
      legacy: [Object],
      cursor: [Object],
      data: {},
      cookies: [],
      _variables: [PostmanVariableScope],
      environment: [PostmanVariableScope],
      collectionVariables: [PostmanVariableScope],
      globals: [PostmanVariableScope],
      request: [PostmanRequest],
      return: [Object],
      response: [PostmanResponse]
    }
  }
]

```

Thanks in advance  
Aurélien

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [September 10, 2020, 5:36pm UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/2 "2020-09-10T17:36:33Z")

</div>

Hi @aurelien.lair,

I believe these are the results of tests scripts executed in the collection run. If you’re getting 3, I assume you have 3 test scripts.

The environment variables provided to the collection run via newman should be the same across all these test executions, so whether you pull them from the first, the last, or somewhere in-between shouldn’t make a difference.

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![aurelien.lair](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@aurelien.lair](https://community.postman.com/u/aurelien.lair)\
**Post date:** [September 14, 2020, 9:21am UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/3 "2020-09-14T09:21:40Z")

</div>

Hi Kevin and thanks for answering. About this statement

> I believe these are the results of tests scripts executed in the collection run. If you’re getting 3, I assume you have 3 test scripts.

Could you precise what you meant please? Are you talking about 3 test scripts within

- the entire collection
- the collection on the specific folder
- the collection on the specific folder on a specific request

Cause that log is the output after running 1 request on that folder of that collection but I do not have 3 test scripts but only 1.

```auto
pm.test("Check http status code", function () {
  pm.response.to.have.status(200);
});

```

I can anyway follow your suggestion about the environment variables but was curious to understand what you meant about the meaning (specifically) of that array in that context.

Thanks  
Aurélien

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [September 14, 2020, 4:00pm UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/4 "2020-09-14T16:00:00Z")

</div>

@aurelien.lair,

Sure, I can explain. The collection gets stored as a JSON file. In that JSON structure, we can find script declarations at each level of the collection hierarchy (root, folder, request). Your newman options will determine what’s actually executed (e.g., entire collection, single folder, etc.).

You’re seeing 3 executions for one of a few reasons:

1. You have 3 different requests with some value saved as a test script.
2. You have a value saved as a test script in at the folder- or collection-level.
3. Some combination of 1 & 2.

Now, an interesting anomaly that occurs here is that if you’ve ever entered the Tests tab of the collection, folder, or request level and saved in the app, the value of the test script in the JSON file might be an empty string (`""`). I believe this still shows up as an execution in this case, even though nothing was technically “executed”.

You can actually check if this anomaly is being hit by changing your log statement to:

```auto
}).on('test', (err, args) => {
  console.log(args.executions.map((ex) => ex.script.exec));
});

```

If you have empty test values, you’ll get an output like this:

```auto
[
  [''],
  [
    'pm.test("Status code is 200", function () {',
    ' pm.response.to.have.status(200);',
    '});'
  ]
]

```

Notice the first element of the output array is an array with an empty string.

Hope this helps.

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![aurelien.lair](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@aurelien.lair](https://community.postman.com/u/aurelien.lair)\
**Post date:** [September 15, 2020, 8:35am UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/5 "2020-09-15T08:35:27Z")

</div>

Hi Kevin,

thanks for answering 🙂  
Regarding

> You have a value saved as a test script in at the folder- or collection-level.

I guess you meant a use case where I am in a test script context saving a value isn’t it?  
If yes then I guess it’s like you were suspecting:

```auto
pm.test("Check http status code", function () {
  pm.response.to.have.status(200);
});

var body = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", body.access_token);

```

And indeed when I run with the `console.log` I get what you were saying:

```auto
[
  [''],
  [''],
  [
    'pm.test("Check http status code", function () {',
    ' pm.response.to.have.status(200);',
    '});',
    '',
    'var body = JSON.parse(responseBody);',
    'postman.setEnvironmentVariable("token", body.access_token);'
  ]
]

```

I just don’t understand well you call it “anomaly”… Is it a bad thing to do it?

Best  
Aurélien

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [September 16, 2020, 7:20pm UTC](https://community.postman.com/t/arg-executions-in-test-event/15764/6 "2020-09-16T19:20:47Z")

</div>

Hi @aurelien.lair,

I’m calling it an “anomaly”, because it’s not intuitive that an empty script would show up in the results. Arguably, it may not be a “bug”, but it is unexpected at the very least. More than likely, it’s harmless for your use case.

Best,

Kevin
