Currently I'm working with writing test script that can read and compare the values return from api and json file I provided. The problem is that I'm not sure the error is in the script or json file.
error returning : JSONError: Unexpected token u in JSON at position 0
json file name (Book1.json)
[
{
"name": "Test Case 1",
"tests": [
{
"testName": "Test 1",
"location": {
"row": 5,
"column": 12
},
"expectedResult": "1023.00"
},
{
"testName": "Test 2",
"location": {
"row": 7,
"column": 10
},
"expectedResult": "500.50"
}
]
},
{
"name": "Test Case 2",
"tests": [
{
"testName": "Test 3",
"location": {
"row": 2,
"column": 8
},
"expectedResult": "750.25"
}
]
}
]
Test script :-
const responseJson = pm.response.json();
var data = JSON.parse(responseBody);
var investmentLink = data.result;
// Write a script that can read the JSON file provided and compare the actual and expected results
const jsonData = JSON.parse(pm.iterationData.get("Book1.json"));
// Write a script that can read the JSON file provided and compare the actual and expected results
function performTests(testCase) {
const tests = testCase.tests;
tests.forEach((test) => {
const testName = test.testName;
const location = test.location;
const expectedResult = test.expectedResult;
const row = location.row;
const column = location.column;
const actualData = investmentLink.reportPIIllustrationTable[0].illustration[row - 1][`column${column}`].data;
pm.test(testName, () => {
pm.expect(actualData).to.equal(expectedResult);
});
});
}
jsonData.forEach((testCase) => {
const testCaseName = testCase.name;
pm.test(testCaseName, () => {
performTests(testCase);
});
});
As I look into the error it shows something might wrong with the json file. Someone may help with this issue