Cypress version 10.3.0
I have a following test.cy.js, which is async IT block.
///
import loadFileObjects from '../../../support/load_file_objects'
var fixtureUrl = '/test/mydata/'
describe("TC1_getResidentialInfo", () => {
var load_test_case;
it('Validate and load all automation feeds', async () => {
load_test_case = await loadFileObjects.getJsonObj(fixtureUrl + '/CUP-575-TC1-TC.json');
})
})
support/load_file_objects.js
class load_file_objects{
//it should accept fixture folder structure and test case name
//returns json object directly using promise
getJsonObj(testCasePath){
// return new Cypress.Promise((resolve, reject) => {
return new Cypress.Promise((resolve, reject) => {
cy.fixture(testCasePath).then((data) => {
cy.log("Test Data for "+testCasePath+ ": " +JSON.stringify(data))
resolve(data)
})
// do something custom here
})
// var data = data;
// return data
// })
}
}
export default load_file_objects
Its working fine when I run the same test using cypress open(Test runner UI) Please let me what I am missing here.
The class instance needs to be created somewhere.
Convention is class names are capitalized. This is the clean way to do it
or
Requiring the fixture
If the path to your fixture file is fixed and consistent, then you can use
require()
at the top of the script to do the async/await heavy lifting for you.