I have multiple JSON file in fixtures folder. The below one is 'studDetails.json'. Based on this file, I have to branch out to other json files.
[
{
"StudentId": "1001",
"StudentName": "Tim Blanks",
"StudentDept": "English"
},
{
"StudentId": "1002",
"StudentName": "Alec Stoinis",
"StudentDept": "Physics"
},
{
"StudentId": "1003",
"StudentName": "Fiona Woods",
"StudentDept": "English"
},
]
I am using the below code in Cypress to read the data from one JSON file and use that data to read another JSON file. I want to work with student's department as English.
const studList = require('../../fixtures/studDetails.json')
describe('Get Student Details', function() {
studList.forEach(stud => {
let studentId = stud.StudentId;
let studentName = stud.StudentName;
let studDept = stud.StudentDept;
if(studDept === "English"){
const deptList = require('../../fixtures/'+ studDept +'.json');
deptList.forEach(dept => {
let deptLead = dept.LeaderName;
let deptController = dept.Controller;
it('Login Test', function() {
cy.visit('http://localhost:8081/login/');
cy....
cy....
cy.get('#deptHead1').set(deptLead);
cy.get('#deptHead2').set(deptController);
});
}
});
When executed, the below error prompted:
No tests found. Cypress could not detect tests in this file.
So, I moved the 'if' block inside the test. Now, it got executed. In the results, I was expecting only 2 tests related to 'English' records from 'studDetails.json' should get displayed and passed. But, there were 3 tests passed. The 1st and 3rd were related to student department 'English'. 2nd test was related to 'Physics' also ran and when expanded in test runner, it showed
'No commands were issued in this test.'
I need to execute only the chosen records from JSON (stud. department as English). Are there any option to run the test inside the 'if' block (or) is it possible to exclude records that's not required in run as it is unnecessarily displaying in the results finally.