I am trying to create some e2e tests for my react application and some behavior is dictated by a json config file from the application. Is there a way to update that json file before a cypress test is executed? I was thinking at BeforeEach
hook, but I don't know how to update that file so that I can cover as much as possible scenarios with my tests.
I am using react 16.14.
You would need to update the json file before the app is started (before cy.visit()
) presuming React reads the file on startup and not after the user takes an action.
Ref cy.readFile()
For JSON, the contents yielded are parsed into JavaScript and returned
describe('test my app', () => {
before(() => {
cy.readFile('app-start.json').then(data => {
// modify the data objext
cy.writeFile('app-start.json', data)
})
})
beforeEach(() => {
cy.visit('/')
})
...
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.