I have developed the following code on an index file
Cypress.Commands.add('component', (name) => {
let log = Cypress.log({
'displayName': 'component',
'name': name
});
cy
.window({ log: false })
.then($win => {
const component = name === 'root' ? $win.app : $win.app.$children.find(e => e.$vnode.tag.includes(name))
log.set({
consoleProps: () => {
return { component };
}
});
return component;
});
})
Test are working fine if i use cy.component inside the test (it) but that force me to use it call it lot of times since I have to call it for all test.
I would like to initialize the component only once on a beforeEach hook and then re-use it on each test.
How can I do that?
This is the code for the tests
onst { LoginPage } = require("../support/pages/pages")
const loginPage = new LoginPage()
const email = "fabryotranto@gmail.com"
const password = "12345"
describe('login feature', () => {
beforeEach('it opens the url', () => {
cy.visit("http://localhost:3000/")
cy.component('root')
.then(root => {
root.showLoginModule = true
})
})
it('register with valid credentials', () => {
cy.component('Login')
.then(login => {
login.logSignSwitch()
login.signupEmail = email
login.signupPassword = password
});
cy
loginPage.clickSignUpButton
cy.get(loginPage.loggedUser)
.should("contain.text", "Log out")
})
if a create another test (it) I would have to call cy.component('Login') again
Thank you all in advance