96 lines
2.9 KiB
JavaScript
96 lines
2.9 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) => { ... })
|
|
|
|
// Importar dinámicamente todos los archivos con el sufijo .commands.js dentro de la carpeta src/test/cypress/integration
|
|
const requireCommands = require.context(
|
|
'../integration',
|
|
true,
|
|
/\.commands\.js$/
|
|
);
|
|
// Iterar sobre cada archivo y requerirlo
|
|
requireCommands.keys().forEach(requireCommands);
|
|
|
|
// Common commands
|
|
Cypress.Commands.add('selectOption', (selector, option) => {
|
|
cy.waitForElement(selector);
|
|
cy.wait(400);
|
|
cy.get(selector).click();
|
|
cy.get('.q-menu .q-item').contains(option).click();
|
|
});
|
|
|
|
Cypress.Commands.add('getValue', selector => {
|
|
cy.get(selector).then($el => {
|
|
if ($el.find('.q-checkbox__inner').length > 0) {
|
|
// retornar el valor del atributo aria-checked
|
|
return cy.get(selector).invoke('attr', 'aria-checked');
|
|
} else {
|
|
return cy.get(selector).invoke('val');
|
|
}
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
|
|
cy.get(element, { timeout }).should('be.visible');
|
|
});
|
|
|
|
Cypress.Commands.add('dataCy', (dataTestId, attr = 'data-cy') => {
|
|
return cy.get(`[${attr}="${dataTestId}"]`);
|
|
});
|
|
|
|
Cypress.Commands.add('getSessionStorage', key => {
|
|
cy.window().then(window => window.sessionStorage.getItem(key));
|
|
});
|
|
|
|
Cypress.Commands.add('getLocalStorage', key => {
|
|
cy.window().then(window => window.localStorage.getItem(key));
|
|
});
|
|
|
|
Cypress.Commands.add('setLocalStorage', (key, value) => {
|
|
cy.window().then(window => {
|
|
window.localStorage.setItem(key, value);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('setSessionStorage', (key, value) => {
|
|
cy.window().then(window => {
|
|
window.sessionStorage.setItem(key, value);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('resetDB', () => {
|
|
cy.exec('pnpm run db');
|
|
});
|
|
|
|
Cypress.Commands.add('setConfirmDialog', () => {
|
|
cy.dataCy('confirmDialogButton').should('exist');
|
|
cy.dataCy('confirmDialogButton').click();
|
|
});
|
|
|
|
Cypress.Commands.add('checkNotify', (status, content) => {
|
|
if (content) cy.dataCy(`${status}Notify`).should('contain', content);
|
|
else cy.dataCy(`${status}Notify`).should('exist');
|
|
});
|