I have fixture file named alerts-escalation-param.params.json where I store operations with their fixture path file ,then I have a function command getOperationData
that get the operation data to use it in the test cases just by calling the operation name .
so the problem that I have is that when I start the tests , in the case when I start using this function getOperationData
I get this error:
cy.each() can only operate on an array like subject. Your subject was: Object{4}
Learn more
here is the function getOperationdata
:
Cypress.Commands.add('getOperationData', (mode, operationsArrayName = 'operations') => {
cy.fixture('alerts-escalation-param.params.json').then((params) => {
const fixturePath = params[operationsArrayName];
cy.fixture(fixturePath).then((data) => {
const opData = data.filter((element) => element.mode === mode);
Cypress.env('fixtureData', opData);
});
});
});
and here is the case test where I use it :
it.only('should do a search by criteria', () => {
cy.getOperationData('search').each((searchCase) => {
cy.setDataAndSearch(searchCase.criteria)
if (searchCase.expectedRowsCountResult === 0) {
cy.should(
'equal',
cy.getdefaultOperationExpectedValue()
.numberOfColumnsOnEmptyRow
)
} else {
cy.should(
'equal',
searchCase.expectedRowsCountResult
)
cy.searchAndGoToDetails(searchCase.criteria)
for (const dataKey in searchCase.afterOpCriteria) {
cy.should(
'equal',
searchCase.afterOpCriteria[dataKey]
)
}
cy.back()
}
})
})