Vấn đề lớn nhất của challenge này chính là cách lấy thông tin từ json object. Có 1 vài nhắc nhở như sau:
- Nếu lấy từ array [] thì phải có vị trí index.
- Nếu lấy từ key mà có space thì dùng [‘key’], thay vì dấu . Ví dụ:
["Material Id"] --> right .Material Id --> wrong
Đây là cách viết test trên postman
const res = pm.response.json();
pm.test("check id", () =>{
const id = res.Result.Response[0]["Material Id"]; // index 0
pm.expect(id.length).to.eql(14);
});
pm.test("check Department", () =>{
const dep = res.Result.Response[0]["Material Department"];
pm.expect(dep).to.eql("OT");
});