Getting Error in Validation

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);
});

The undefined is coming from here.

const aisle_id = pm.collectionVariables.get(“ais”);

Do you have a collection variable called “ais”?

It doesn’t look like it.

//random aisle
const ais= pm.variables.replaceIn(‘{{$randomInt}}’);
pm.collectionVariables.set(“aisle”,ais);

The collection variable is called “aisle” not “ais”.

Please use the preformatted text option in the editor when pasting code or JSON, as its stops everything from being aligned to the left (and therefore really hard to read).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.