首页 > 解决方案 > Can I provide a json path in CSV file in postman

问题描述

I was trying to execute a postman collection that has many iteration. Data was provided in CSV format.

In each iteration i want to compare different nodes with expected messages provided in the datafile, for example,

sample collection:

{
    "message": [{
        "code": XYX,
        "abc": "how are you",
        "def": "where are you from"
        "ghi": "your name",
        "jkl": "place"
    }]
}

in 1st iteration - my test is as below

pm.response.json().message[0].code.to eql(data.ExpectedErrorMessage);

2nd iteration,

pm.response.json().message[0].abc.to eql(data.ExpectedErrorMessage); 

and so on.

I have 100 + nodes and many arrays in the list. so its not feasible to write test for each node separately. Instead, i want to write a generic test and keep the response path in CSV file.

I tried by providing the path in below way in my data file.But i am unable to perform my test. I am getting the assertion error

[
  {
    "TC_ID": "TC_001",
    "TC_NAME": "abc",
    "path": "pm.response.json().message[0].code",
    "ExpectedErrorMessage": "XYZ"
  },
  {
    "TC_ID": "TC_002",
    "TC_NAME": "def",
    "path": "pm.response.json().message[0].abc",
    "ExpectedErrorMessage": "how are you"
  }
]

标签: javascriptjsonpostmandata-driven-tests

解决方案


推荐阅读