Data driven Approach

Hi Team,

I am using the csv file where I’m putting all data with respective fields.

a sample of the JSON response:

"rank": {

            "id": 0,

            "description": "OPTAVIA Coach"

        },

Now one of the values is "OPTAVIA Coach" for which I am making the script as

pm.test("data Verification", function () {
    var jsonData = pm.response.json();
pm.expect(jsonData[0].rank.description).to.eql(String(data.description));
});

But getting error as data Verification | AssertionError: expected ‘OPTAVIA Coach’ to deeply equal ‘OPTAVIA Coach’

Note: observed when string without space of special character, script working fine no issue.
Any Solution for this?

@allen.helton @sivcan @dannydainton

It might be the way you’re casting it to a string. Why don’t you try taking out the cast?

pm.test(“data Verification”, function () {
   var jsonData = pm.response.json();
   pm.expect(jsonData[0].rank.description).to.eql(data.description);
});

Tried but had no luck.Even tried with Number casting too but not working.

Hey @aakashjain8693

What does the CSV file look like?

Can you add the full response body and not a sample of it please, it looks like something is missing and it would be easy to run it locally it it’s all there :smiley:

I’m not really sure what this is supposed to be doing in the expect statement:

String(data.description);

Have you tried referencing the data in the CSV file like this:

pm.expect(jsonData[0].rank.description).to.eql(pm.iterationData.get('<The CSV Column Name of the Value >'));

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#pmiterationdata

1 Like

Response Body:

[

    {

        "id": "100067191",

        "customerTypeId": 2,

        "firstName": "Tanya R.",

        "lastName": "Smith",

        "nextScheduledPremierOrder": {

            "cv": null,

            "qv": null,

            "orderType": null,

            "scheduledOn": null,

            "price": {

                "total": null

            }

        },

        "rewards": {

            "balance": null

        },

        "rank": {

            "id": 0,

            "description": "OPTAVIA Coach"

        },

        "certified": "0",

        "licensed": "",

        "phoneNumber": "916-617-0194",

        "businessEmail": "tanchel60@hotmail.com",

        "accountEmail": "tanchel60@hotmail.com",

        "address": {

            "line1": "637 Fourness Dr",

            "line2": null,

            "city": "West Sacramento",

            "state": "US-AK",

            "postalCode": "95605-2223",

            "countryCode": "US-AK"

        },

        "socialAccounts": {

            "facebook": {

                "url": null,

                "username": null

            },

            "instagram": {

                "url": null,

                "username": null

            },

            "twitter": {

                "url": null,

                "username": null

            }

        },

        "highestAchievedRank": {

            "id": 0

        },

        "volume": {

            "pqv": "0.0000",

            "fqv": "0.0000",

            "gen0Qv": "0.0000",

            "gqv": "0.0000"

        },

        "activationOn": null,

        "businessCoach": {

            "id": "5",

            "firstName": "Company",

            "lastName": "Account",

            "rank": {

                "id": 70

            }

        },

        "globalDirector": {

            "id": "30118781",

            "firstName": "Paula",

            "lastName": "Bryan",

            "rank": {

                "id": 110

            }

        },

        "presidentialDirector": {

            "id": "2591401",

            "firstName": "Lisa",

            "lastName": "Castro",

            "rank": {

                "id": 140

            }

        },

        "earnedQsb": 0,

        "orderingEntitiesCount": 0

    }

]
pm.expect(jsonData[0].rank.description).to.eql(pm.iterationData.get('description'));
Tried but not working,  error exist:  expected 'OPTAVIA Coach' to deeply equal 'OPTAVIA Coach'

Sheet I cant attach but its very simple where as coulmn header as “description” and value as “OPTAVIA Coach”.

cc @gopagonirakesh98

Thanks @dannydainton for the solution.
Solution: Basically few string values contains some other characters which were hidden in .csv file but you can see them on atom so just remove them and try again, it will work.