I have a custom command where I want to override the default timeout of 4 seconds. I tried setting the timeout in the command's code and in the tests that use it but with no success yet.
Cypress.Commands.add("login", () => {
Auth.signIn(username, password)
.then(() => {
console.log('Programmatically logged in as ' + username);
})
.catch(err => console.log('Error when login in: ', err));
})
I attempted the following:
Cypress.Commands.add("login", { timeout : 10000} () => {...}
and
Cypress.Commands.add("login", () => {
Auth.signIn(username, password)
.then(({ timeout : 10000}) => {
console.log('Programmatically logged in as ' + username);
})
.catch(err => console.log('Error when login in: ', err));
})
EDIT/UPDATE
I added async/await to the Auth.signIn()
call and that makes the execution wait for that method to finish, but if it reaches the 4 seconds default timeout it makes the test fail.
The best I could do was include all the test code inside the then
of the login
command.
it('Test that requires login', () => {
cy.login().then(function (){
cy.visit('/');
//...
});
})
Although the test waits for the login operation to finish, it fails if the timeout is reached before it is logged in.
cy.visit
– MauriRcy.get('loginFormElement').should('be.visible')
aftercy.visit()
and before the test starts – Rosen Mihaylov