Onload() function in Cypress

Viewed 717

I'm making an end to end test, I want to use onload() function to load all the elements before execution but error found "Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise." the code below:

const loginpage = new loginPage();

cy.visit("/globalview/login",{ timeout: 50000, 


  onLoad: function(contentWindow){

   cy.log('globalview')
   loginpage.FillEmail("");
   loginpage.FillPassword("");
   loginpage.SubmitLogin();

   }
})

How can I fixed this issue?

1 Answers

The doc says cy.visit() resolves when the remote page fires its load event. So it seems you can do your logging actions just after the visit command:


    const loginpage = new loginPage();
    
    cy.visit("/globalview/login",{ timeout: 50000}) 
    
    cy.log('globalview')
    loginpage.FillEmail("");
    loginpage.FillPassword("");
    loginpage.SubmitLogin();

})

But this will work if you loginpage's methods are expected to work outside of the cypress loop (i.e. calling other cypress commands)

Related