I need to get through the data Table an object array, using cucumber in cypress In the cucumber file:
Given must present the values in the requisition body.
| userid | segmentation | date|
| 111 | [{"DateType": "day"} ] | {"StartDate": "1992-12-26", "EndDate": "2061-12-26"} |
in the ts file:
Given('must present the values in the request body', (dataTable) => {
const columns = Object.keys(dataTable.hashes()[0]).length;
const rows = dataTable.hashes().length;
body = dataTable.hashes();
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
if(Object.values(body[i][j]).includes("{", 0)){
console.log(Object.keys(body[i])[j]);
console.log( (body[i])[j])
body[i][j] = JSON.parse(Object.values(body[i])[j])
}
}
}
console.log(body)
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
expect(JSON.stringify(response.body)).to.have.string(JSON.stringify(Object.values(body[i])[j]));
}
}
})
I'm using typescrip and when reading the table I can't convert this segmentation into an object array or date into an object, can someone tell me if this is possible and how to do it?