Postman Script: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==Scripting==
==Before Request==
<source lang="js">
var moment = require("moment");
(function(pm, moment, today, adultBithDateMin, adultBithDateMax){
    adultBithDateMin = moment(today).subtract(18, 'years').add(1, 'days').format("DD/MM/YYYY");
    adultBithDateMax = moment(today).subtract(66, 'years').format("DD/MM/YYYY");
    pm.setEnvironmentVariable('adult.birth.date.min', adultBithDateMin);
    pm.setEnvironmentVariable('adult.birth.date.max', adultBithDateMax);
    console.info("Adult Min birth Date: " + adultBithDateMin);
    console.info("Adult Max birth Date: " + adultBithDateMax);
}(postman, moment, new Date()));
</source>
==After Request==
<source lang="js">
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("quotationRefId", jsonData.refId);
pm.test("Successful Quotation", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.message).to.eql("Quotation has been created successfully.");
});
</source>
==References==
==References==
{|
{|

Revision as of 08:15, 19 July 2021

Scripting

Before Request

var moment = require("moment");
(function(pm, moment, today, adultBithDateMin, adultBithDateMax){
    adultBithDateMin = moment(today).subtract(18, 'years').add(1, 'days').format("DD/MM/YYYY");
    adultBithDateMax = moment(today).subtract(66, 'years').format("DD/MM/YYYY");
    pm.setEnvironmentVariable('adult.birth.date.min', adultBithDateMin);
    pm.setEnvironmentVariable('adult.birth.date.max', adultBithDateMax);
    console.info("Adult Min birth Date: " + adultBithDateMin);
    console.info("Adult Max birth Date: " + adultBithDateMax);
}(postman, moment, new Date()));

After Request

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("quotationRefId", jsonData.refId);


pm.test("Successful Quotation", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.message).to.eql("Quotation has been created successfully.");
});


References