0
[{
    "FP": "DAV1",
    "SMO": false,
    "SP": [{
        "name": "FOP1",
        "Exam": [{
            "Marksguid": "a02dac4f-630f-4ed0-aa54-8c7044b71f2f",
            "apiUrl": "test1",
            "interval": 65,
            "schemaVersion": "1.2",
            "authenticationType": "Basic"
        }]
    }]
}, {
    "FP": "FOP10",
    "SMO": false,
    "SP": [{
        "name": "FOP10",
        "Exam": [{
            "Marksguid": "f778dd51-d401-42ca-a5ea-4920db5708b2",
            "apiUrl": "test1",
            "interval": 65,
            "schemaVersion": "1.2",
            "authenticationType": "Basic"
        }]
    }]
}, {
    "FP": "FOP2",
    "SMO": false,
    "SP": [{
        "name": "FOP2",
        "Exam": [{
            "Marksguid": "8c49f158-7286-4f15-904c-564b41966b6b",
            "apiUrl": "test1",
            "interval": 65,
            "schemaVersion": "1.2",
            "authenticationType": "Basic"
        }]
    }]
}, {
    "FP": "FOP3",
    "SMO": false,
    "SP": [{
        "name": "FOP3",
        "Exam": [{
            "Marksguid": "c5f2893f-b8fb-4494-8126-b3de47ebe440",
            "apiUrl": "test1",
            "interval": 65,
            "schemaVersion": "1.2",
            "authenticationType": "Basic"
        }]
    }]
}]

I want to do assertion for "FP": "FOP2", and the underneath name and exam all those stuff. Could someone help me on this.

pavelsaman
  • 7,399
  • 1
  • 14
  • 32

1 Answers1

0

First of all, you parse the response body:

const responseJson = pm.response.json();

then you can access the data via responseJson variable.

There's an array, and you're interested in FP properties, so you can get only those:

const fps = responseJson.map(arr => arr.FP);

finally you can assert there's FOP2 present:

pm.expect(fps).to.include.members(["FOP2"]);

So the whole check could look like this:

pm.test("Array contains 'FOP2'", () => {
  const responseJson = pm.response.json();
  const fps = responseJson.map(arr => arr.FP);

  pm.expect(fps).to.include.members(["FOP2"]);
});

and the underneath name and exam all those stuff

I don't exactly know what you want to assert there, you'd need to be more specific. But perhaps you can continue on your own after my example.

pavelsaman
  • 7,399
  • 1
  • 14
  • 32
  • Thank you!! I'm getting error like this Array contains 'FOP2' | AssertionError: expected [ Array(42) ] to have the same members as [ 'FOP2' ] – dhiwakaran arumugam Oct 28 '21 at 01:09
  • I've used the same thing you have give pm.test("Array contains 'FOP2'", () => { const responseJson = pm.response.json(); const fps = responseJson.map(arr => arr.FP); pm.expect(fps).to.have.members(["FOP2"]); }); – dhiwakaran arumugam Oct 28 '21 at 01:10
  • "FP": "FOP2", "SMO": false, "SP": [{ "name": "FOP2", "Exam": [{ "Marksguid": "8c49f158-7286-4f15-904c-564b41966b6b", "apiUrl": "test1", "interval": 65, "schemaVersion": "1.2", "authenticationType": "Basic" }] }] Also when I "FP": "FOP2", I need to assert "SMO": false, and following parameter aswell "SP": [{ "name": "FOP2", "Exam": [{ "Marksguid": "8c49f158-7286-4f15-904c-564b41966b6b", – dhiwakaran arumugam Oct 28 '21 at 01:40
  • My Question: 1. I want to assert “FP”: “FOP2”. 2. And If 1st step is success. I want to Assert “SMO”: false, 3. And also I need to Assert SP.name.FOP2 and its corresponding Exam.“Marksguid”: – dhiwakaran arumugam Oct 28 '21 at 02:31
  • @dhiwakaranarumugam: there is one change in my post now, it should be `pm.expect(fps).to.include.members(["FOP2"]);`, because `fps` is a superset of the expected array. that's why you got the error. more on thet in docs https://www.chaijs.com/api/bdd/#method_members – pavelsaman Oct 28 '21 at 07:05
  • Thank you so much it works well. I have another question. Is there a way to MYSQL database and select (get) a row of data from the table and can we use it in a Postman.. – dhiwakaran arumugam Oct 28 '21 at 17:45
  • This works very well – dhiwakaran arumugam Nov 08 '21 at 18:15