# Collection Runner fails a test that succeeds when run manually

**URL:** <https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json\
**Created:** [June 5, 2020, 9:26pm UTC](https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170 "2020-06-05T21:26:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacksos](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jacksos/32/4643_2.png) [@jacksos](https://community.postman.com/u/jacksos)\
**Post date:** [June 5, 2020, 9:26pm UTC](https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170/1 "2020-06-05T21:26:16Z")

</div>

Hi, I’m having a problem where the collection runner is failing a test that succeeds when run manually.

My test checks to see if the response from the server contains the staff number I sent in.  
I have a CSV data file with four staff numbers and an environment variable with the same {{StaffNumber}} template set as one of the test staff numbers.

```
pm.test("Response contains correct user", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.staffnumber).to.equal(pm.iterationData.get("staffnumber"));
});

```

When the request is run manually, this test passes as I would expect it to. However if I run it using the collection runner with a data file, the test fails with the result:

```
AssertionError: expected undefined to equal 40000871

```

.. rinse and repeat for every staff number in the data file.  
When I inspect each runner iteration, the response body does infact have the correct value there, in exactly the same format as when I run it manually.

What am I doing wrong here that I can’t figure out?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 5, 2020, 9:52pm UTC](https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170/2 "2020-06-05T21:52:05Z")

</div>

Hey @jacksos

Welcome to the community!! 🚀

Just due to the relationship between the request builder and the Collection Runner, are you saving the changes in the Request before running them through the runner? Basically, is there a little orange dot on the request tab.

Could you share an example of the response body, just so we can check that out please?

Is it `staffnumber` or `staffNumber` in the response?

You could also try adding `console.log(jsonData)` before the `pm.expect()` line, just so you can see what that variable is returning, might be something going on in there?

---

<div class="post-metadata">

**Author:** ![jacksos](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jacksos/32/4643_2.png) [@jacksos](https://community.postman.com/u/jacksos)\
**Post date:** [June 5, 2020, 10:07pm UTC](https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170/3 "2020-06-05T22:07:08Z")

</div>

Hi there @danny-dainton,

Thanks for the reply!  
While I was in the console I noticed the capitalization on the jsonData.staffnumber was wrong.  
Correcting it switched the error response around and succeeded in the runner but not manually.

I’ve realised that while not in a collection runner session that pm.iterationData is null.  
So where I was getting successes before, was because both side of the test equal undefined.

So I have corrected my test to include a check and run a different but still validating test, which has resolved my issue.

```
pm.test("Response contains correct user", function () {

    var respData = pm.response.json();

    if (pm.environment.get('runner') == 'true')
    {
        pm.expect(respData.staffNumber).to.equal(pm.iterationData.get("StaffNumber"));
    }
    else {
        pm.expect(respData.staffNumber).to.equal(parseInt(pm.environment.get("StaffNumber"), 10));
    }
    
});

```

Apologies, that was a stupid mistake. 😅  
But thanks for mentioning the console which poked me in the right direction!

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 5, 2020, 10:19pm UTC](https://community.postman.com/t/collection-runner-fails-a-test-that-succeeds-when-run-manually/13170/4 "2020-06-05T22:19:03Z")

</div>

Glad you got it sorted!! If you get stuck again, feel free to reach out for help!! 🏆
