Mar 14, 2025
pm library for assertionsNormal Functions
function myFunction() {
// function body
}
Arrow Functions
const myFunction = () => {
// function body
}
pm.test() to write assertionspm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Content-Type header is present", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("Content-Type is application/json", function () {
pm.response.to.have.header("Content-Type", "application/json");
});
pm.test("Language cookie is present", function () {
pm.cookies.has("language");
});
pm.test("Language cookie value is en-GB", function () {
pm.expect(pm.cookies.get("language")).to.equal("en-GB");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
const jsonData = pm.response.json();
pm.test("ID is a number", function () {
pm.expect(jsonData.id).to.be.a('number');
});
pm.test("Name is a string", function () {
pm.expect(jsonData.name).to.be.a('string');
});
pm.expect(jsonData.courses).to.include('Java');
pm.expect(jsonData.courses).to.have.members(['Java', 'Selenium']);
pm.expect(jsonData.name).to.equal("John");
pm.expect(jsonData.location).to.equal("India");
pm.test("Schema is valid", function () {
pm.expect(tv4.validate(jsonData, schema)).to.be.true;
});