I am trying to get the request body raw inside test cases in TESTS scripts?
Here the script in TESTS:
pm.sendRequest({
url: pm.collectionVariables.get("url") + '/xxxxx/' + api + '/xxxxxxxxxxx',
method: 'POST',
header: {
'content-type': 'application/json',
'application': pm.collectionVariables.get("sha256"),
'sign': pm.collectionVariables.get("sign")
},
body: {
mode: 'raw',
raw: JSON.stringify({
deviceId: null,
email: null
})
}
}, console.log(“Request Body: ”, JSON.parse(pm.request.body.raw)),
function(err, res) {
pm.test(“N: All Parameter Null”, function() {
pm.expect(res).to.have.property(‘code’, 200);
pm.expect(res.json()).to.have.property(‘status’, ‘00’);
pm.expect(res.json()).to.have.property(‘message’, ‘Success’);
console.info("All Parameter Null Response Time: " + res.responseTime)
});
})
I’m using console.log(“Request Body :”, JSON.parse(pm.request.body.raw)) to get request body raw, but the content i got is the raw data from BODY (Main Test Cases)
the purpose of this question is to create a signature in the header, based on request body raw that generated with secret key
i have no problem to create signature in BODY (Main Test Cases), the problem only inside TESTS
How can I get the request body from TESTS ?
or anyone experience how to create signature inside TESTS?