82 lines
2.5 KiB
JavaScript
82 lines
2.5 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('login', user => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/Accounts/login',
|
|
body: {
|
|
user,
|
|
password: 'nightmare'
|
|
}
|
|
}).then(response => {
|
|
window.localStorage.setItem('token', response.body.token);
|
|
cy.request({
|
|
method: 'GET',
|
|
url: '/api/VnUsers/ShareToken',
|
|
headers: {
|
|
Authorization: window.localStorage.getItem('token')
|
|
}
|
|
}).then(({ body }) => {
|
|
window.localStorage.setItem(
|
|
'tokenMultimedia',
|
|
body.multimediaToken.id
|
|
);
|
|
});
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('loginFlow', user => {
|
|
cy.visit('/#/login');
|
|
cy.get('[data-testid="loginUserInput"]').type(user);
|
|
cy.get('[data-testid="loginPasswordInput"]').type('nightmare');
|
|
cy.get('button[type="submit"]').click();
|
|
cy.url().should('contain', '/#/cms/home');
|
|
});
|
|
|
|
Cypress.Commands.add('logout', user => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: 'Accounts/logout'
|
|
}).then(response => {
|
|
localStorage.clear();
|
|
sessionStorage.clear();
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
|
|
cy.get(element, { timeout }).should('be.visible');
|
|
});
|
|
|
|
Cypress.Commands.add('changeLanguage', language => {
|
|
const languagesOrder = ['en', 'es', 'ca', 'fr', 'pt'];
|
|
const index = languagesOrder.indexOf(language);
|
|
cy.visit('/#/login');
|
|
cy.waitForElement('[data-testid="switchLanguage"]');
|
|
cy.get('[data-testid="switchLanguage"]').click();
|
|
cy.get('.q-menu .q-item').eq(index).click(); // Selecciona y hace clic en el tercer elemento "index" de la lista
|
|
});
|