Estos son los comandos personalizados que he añadido:
Cypress.Commands.add("login", (email, password) => {
const userInput = "#user_login";
const passwordInput = "#user_password";
const loginButton = "#login_form > div.form-actions > input";
cy.visit("<Login page>");
cy.get(userInput).should("be.visible").type(email);
cy.get(passwordInput)
.should("be.visible")
.type(password, { sensitive: true });
cy.get(loginButton).should("be.visible").click();
return cy;
});
Cypress.Commands.add("is", (chainer) => {
if (chainer === "login.error") {
const error = ".alert.alert-error";
cy.get(error).should("be.visible");
} else if (chainer === "login.success") {
const tabs = {
account_summary_tab: "#account_summary_tab",
account_activity_tab: "#account_activity_tab",
transfer_founds_tab: "#transfer_funds_tab",
};
cy.get(tabs.account_activity_tab).should("be.visible");
cy.get(tabs.account_summary_tab).should("be.visible");
cy.get(tabs.transfer_founds_tab).should("be.visible");
} else {
throw new Error(`${chainer} is not recognized as valid chainer`);
}
return cy;
});
De tal manera que la prueba me queda asÃ:
describe("Login with custom command", () => {
it("error login", () => {
cy.login("aaaa", "aaaa").is("login.error");
});
it("success login", () => {
cy.login("username", "password").is("login.success");
});
});
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?