I am trying to overwrite the Cypress visit method so that it can close the toast when the page is loaded. This is a draft which is trying just to get the element's length.
Cypress.Commands.overwrite('visit', (originalVisit, url, options = {}) => {
options.onLoad = () => {
const len = cy.get(BasePage.genericLocators.notificationToasts.releaseVersionToast).its.length;
console.log(len);
};
return originalVisit(url, options);
});
Continuously facing the following error:
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
The command that returned the promise was:
cy.visit()
The cy command you invoked inside the promise was:
cy.get()
Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.
Cypress will resolve your command with whatever the final Cypress command yields.
This is an error instead of a warning because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.