Validation of id logic | AssertionError: expected ‘DE180undefined’ to deeply equal ‘DE180765’
Prerequest-const code=pm.globals.get(“companycode”);
const val=pm.variables.replaceIn(‘{{$randomInt}}’);
pm.collectionVariables.set(“isbn”,code+val);
//random aisle
const ais= pm.variables.replaceIn(‘{{$randomInt}}’);
pm.collectionVariables.set(“aisle”,ais);
pm.collectionVariables.set(“author_name”,“Rahul shetty”);
Test:-const jsondata= pm.response.json();
console.log(jsondata);
console.log(jsondata.ID);
const book_id= jsondata.ID;
pm.environment.set(“bookid”, book_id);
pm.test(“Validation if response is 200”, function() {
pm.response.to.have.status(200);
pm.expect(jsondata).to.have.property(“Msg”);
pm.expect(jsondata.Msg).to.eql(“successfully added”);
});
pm.test(“Header cookies have content”, function() {
pm.response.to.have.header(“Content-Type”);
pm.expect(pm.response.headers.get(“Content-Type”)).to.eql(“application/json;charset=UTF-8”);
pm.expect(pm.response.responseTime).to.be.below(1200);
pm.expect(pm.response.text()).to.include(“successfully added”);
});
pm.test(“Validation of id logic”, function() {
const isbn_id = pm.collectionVariables.get(“isbn”);
const aisle_id = pm.collectionVariables.get(“ais”);
const expect_id = isbn_id + aisle_id;
pm.expect(expect_id).to.eql(book_id);
});