Files
tuhui/frontend/cypress/support/commands.js
2026-03-08 19:28:32 +08:00

49 lines
1.7 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 custom command for login --
Cypress.Commands.add('login', (phone, password) => {
cy.visit('/');
cy.wait(1000);
cy.get('.btn-login').click();
cy.get('.auth-modal').should('be.visible');
cy.get('input[placeholder*="手机号"]').type(phone);
cy.get('input[placeholder*="密码"]').first().type(password);
cy.get('.auth-modal .auth-submit-btn').click();
cy.wait(3000);
});
Cypress.Commands.add('register', (phone, password, nickname = '测试用户') => {
cy.visit('/');
cy.wait(1000);
cy.get('.btn-register').click();
cy.get('.auth-modal').should('be.visible');
cy.get('input[placeholder*="手机号"]').type(phone);
if (nickname) {
cy.get('input[placeholder*="昵称"]').type(nickname);
}
cy.get('input[placeholder*="设置密码"]').type(password);
cy.get('input[placeholder*="确认密码"]').type(password);
cy.get('.auth-modal .auth-submit-btn').click();
cy.wait(3000);
});
// -- 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) => { ... })