从“响应”下面,我想获取“ responseCode”的值并临时存储。如果值为1,则在控制台上,我要编写“ Test PASS”。任何人都可以共享此测试的代码吗?
{
"data":{
"transactionId":"$1"
},
"responseMessage":"Transaction successfully done. Transaction Id : txn_15594028419901124218",
"responseCode":1
}
我尝试使用以下代码设置变量:
var jsonData = JSON.parse(responseBody);
pm.globals.set("responseCode",jsonData.data.responseCode);
答案 0 :(得分:0)
这个基本的<body onload="carregar()" id="effect">
<div class="container">
<div class="header">
<h1>Hora do dia</h1>
<div class="a">
<p id="msg">Aqui vai aparacer a mensagem</p>
</div>
</div>
<div class="section">
<div class="b">
<img src="amanhecer.jpg" alt="amanhecer" id="imagem">
</div>
</div>
<div class="footer">
<p>©CursoemVideo</p>
</div>
</div>
<script>
function carregar() {
var msg = document.getElementById('msg');
var img = document.getElementById('imagem');
var data = new Date();
var hora = data.getHours();
var effect = document.getElementById('effect')
setTimeout(function () {
$("#effect").fadeOut();
$("body").fadeIn()
})
msg.innerText = `Agora são ${hora} horas`
if (hora >= 0 && hora < 12) {
//bom dia
img.src = 'amanhacer.jpg'
document.body.style.backgroundImage = "url('bg.jpg')"
} else if (hora >= 12 && hora < 18) {
//boa tarde
img.src = 'anoitecer.jpg'
document.body.style.backgroundImage = "url('bg-anoitecer.jpg')";
} else {
// boa noite
img.src = 'noite.jpg'
document.body.style.backgroundImage = "url('bg-noite.jpg')";
}
}
</script>
</body>
将检查响应中的值,存储变量,并将test
写入控制台
Test PASS
这不能说明测试失败并向控制台写入pm.test("Check the Response Code is 1", () => {
pm.expect(pm.response.json().responseCode).to.eql(1);
pm.globals.set("responseCode", pm.response.json().responseCode)
console.log("Test PASS")
});
的情况,无论如何,您还是可以在Postman用户界面中得到的。
如果您不想将其包装在Test FAIL
中,则可以执行以下操作:
test