Jul 5, 2024
pm.response.to.have.status(expectedCode)
, pm.expect(pm.response.code).to.be.oneOf([200, 201])
pm.expect(pm.response.headers.get('Content-Type')).to.equal('application/json')
pm.expect(pm.cookies.has('cookieName')).to.be.true
, pm.expect(pm.cookies.get('cookieName')).to.eql('expectedValue')
pm.expect(pm.response.responseTime).to.be.below(expectedMilliseconds)
const jsonData = pm.response.json();
pm.expect(jsonData.id).to.be.a('number');
pm.expect(jsonData.name).to.be.a('string');
pm.expect(jsonData.courses).to.be.an('array');
pm.expect(jsonData.courses).to.include('Java');
pm.expect(jsonData.courses).to.have.members(['Java', 'Selenium']);
pm.expect(jsonData.id).to.eql(1);
pm.expect(jsonData.name).to.eql('John');
pm.expect(jsonData.courses[0]).to.eql('Java');
pm.expect(jsonData.courses[1]).to.eql('Selenium');
const schema = { /* schema content */ };
const tv4 = require('tv4');
pm.test('Schema is valid', function() {
pm.expect(tv4.validate(jsonData, schema)).to.be.true;
});
chai
and pm
libraries for implementing validation in Postman