Files
bodyshop/client/cypress/support/commands.js
2023-06-26 10:34:33 +08:00

76 lines
2.2 KiB
JavaScript

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Cypress.Commands.add("goToSignInPage", () => {
cy.visit("/");
cy.contains("Sign In").click();
});
Cypress.Commands.add("login", (username, password) => {
cy.goToSignInPage();
cy.get('[data-cy="username"]').type(username);
cy.get('[data-cy="password"]').type(password);
cy.get('[data-cy="sign-in-button"]', { timeout: 2000 }).click();
});
Cypress.Commands.add("passwordReset", (email) => {
cy.goToSignInPage();
cy.get('[data-cy="reset-password"]').click();
cy.get('[data-cy="reset-password-email-input"]').type(email);
cy.get('[data-cy="reset-password-button"]').click();
});
Cypress.on("uncaught:exception", (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false;
});
Cypress.Commands.add("antdSelect", (selector, filter) => {
cy.get(`.ant-select-${selector} > .ant-select-selector`).click();
cy.get(`.ant-select-${selector} .ant-select-selection-search input`)
.invoke("attr", "id")
.then((selElm) => {
const dropDownSelector = `#${selElm}_list`;
cy.get(dropDownSelector)
.next()
.find(".ant-select-item-option-content")
.not(`:contains("${filter}")`)
.first()
.click();
});
});
Cypress.Commands.add("antdFormSelect", (name, text, cb) => {
cy.get(".ant-form-item-required").then(($field) => {
if ($field.text().includes(text)) {
if (name) cy.antdSelect(name);
cb?.();
}
});
});