Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
How to get console log when the test fails POSTMAN

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.

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)}
    });
}}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

pm.expect doesn't return anything , it just throws an Exception (Error) . So you cannot use it in if condition which expects a boolean

Try any of :

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 (jsonData[i].products[j].installment < 100 && jsonData[i].products[j].installment < 100) console.log(jsonData[i].id)
                pm.expect(jsonData[i].products[j].installment).to.be.above(100)
                pm.expect(jsonData[i].products[j].installment).to.be.below(100)
            });
    }
}

Or :

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 () {

                try {
                    pm.expect(jsonData[i].products[j].installment).to.be.above(100)
                } catch (e) {
                    pm.expect(jsonData[i].products[j].installment).to.be.below(100)
                    console.log(jsonData[i].id)
                }

            })
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I use the following to output to console as well as the test window

pm.test(pm.info.requestName + " - Auth Successful", ...);
console.info(pm.info.requestName + " - Auth Successful");

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda