I am doing my first steps in Cypress and issue which I meet is that I replicate the code so I wish to make it better. I've tried to use cy.fixture in a constructor but it failed, so I am looking for a way to use cy.fixture only once in class and assign result to this which can be used in other methods.
class LoginPage{
navigate(){
cy.fixture('urls.json').then((url) => {
cy.visit(url.baseUrl);
})
}
checkIfRedirected(){
cy.reload()
cy.fixture('urls.json').then((url) => {
cy.url().should('equal', url.claimUrl)
})
}
}
It is possible to import the fixture at the top of the LoginPage
import url from './cypress/fixture/urls.json'
class LoginPage {
navigate() {
cy.visit(url.baseUrl);
}
checkIfRedirected(){
cy.reload()
cy.url().should('equal', url.claimUrl)
}
}