Search code examples
postmanpostman-collection-runner

ReferenceError: REVISION is not defined


While reading the JSON response

 "deviceInfo": {
                "SERIALNUMBER": "0815",
                "HW-REVISION": "42"
            }

I faced the reference error mentioned in the title while accessing HW-REVISION.

Please find my code below,

pm.test("To verify that deviceinfo hardware revision is given as expected", function(){
    var jsonData = pm.response.json();
    pm.expect(jsonData.data.device.deviceInfo.HW-REVISION).to.eql("42");
});

Solution

  • The - in HW-REVISION is the problem, since it is no valid char for a variable name.

    jsonData.data.device.deviceInfo.HW-REVISION tries to extract REVISION from jsonData.data.device.deviceInfo.HW

    Instead you can access the variable as following:

    pm.expect(jsonData.data.device.deviceInfo['HW-REVISION']).to.eql("42");