# How to get console log when the test fails?

**URL:** <https://community.postman.com/t/how-to-get-console-log-when-the-test-fails/27744>\
**Category:** Help Hub\
**Tags:** tests, automation, json\
**Created:** [September 11, 2021, 11:25pm UTC](https://community.postman.com/t/how-to-get-console-log-when-the-test-fails/27744 "2021-09-11T23:25:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![UncleMoris](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/unclemoris/32/9658_2.png) [@UncleMoris](https://community.postman.com/u/UncleMoris)\
**Post date:** [September 11, 2021, 11:25pm UTC](https://community.postman.com/t/how-to-get-console-log-when-the-test-fails/27744/1 "2021-09-11T23:25:33Z")

</div>

I have a problem with this test. I want get a `consol.log` when the installment value in my JSON is below 100(when test `FAIL` ). But as result, I have a `PASS` and `FAIL` in test results, that’s work but I can’t get any info in `consol.log` . I don’t know why my code doesn’t work. I thought `else if` give me the expected result. But still, it doesn’t work well.

_ **Test script** _

```auto
var jsonData = JSON.parse(responseBody)

for(var i=0 ; i<=jsonData.length - 1; i++){{

for(var j=0 ; j<=jsonData[i].products.length - 1; j++)

pm.test("Installment > 100", function(){

if (pm.expect(jsonData[i].products[j].installment).to.be.above(100)){}

else if(pm.expect(jsonData[i].products[j].installment).to.be.below(100))
    {console.log(jsonData[i].id)}
    });
}}

```

I don’t know if json should be included in this type of question. Is the code enough?

Thanks  
**Moris**

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [September 12, 2021, 7:52am UTC](https://community.postman.com/t/how-to-get-console-log-when-the-test-fails/27744/2 "2021-09-12T07:52:56Z")

</div>

The reason why this doesn’t work is because whenever a failure occurs by the `pm.expect` it basically throws the error and the error bubbles up from there.  
In JS, if an error is thrown at a certain line, then the succeeding lines aren’t executed.

Similarly, in your case the console log is never executed since before that itself the error is thrown in the `else if` line.

What you’d want do is something like this:

```javascript
const isInstallmentBelow100 = jsonData[i].products[j].installment < 100;

if (isInstallmentBelow100) {
  console.log(jsonData[i].id);
}

// Now make your test pass or fail using the boolean check
pm.expect(isInstallmentBelow100).to.be.false;

```
