2020-05-19 13:13:30 +00:00
|
|
|
// ***********************************************
|
|
|
|
// 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) => { ... })
|
2020-07-03 17:25:23 +00:00
|
|
|
|
|
|
|
/* globals Cypress, cy, expect */
|
|
|
|
|
2020-07-08 13:41:05 +00:00
|
|
|
import 'cypress-localstorage-commands';
|
|
|
|
|
2020-07-03 17:25:23 +00:00
|
|
|
Cypress.Commands.add('login', () => {
|
|
|
|
cy.fixture('admin.json').then(admin => {
|
|
|
|
cy.get('#id_username').type(admin.username);
|
|
|
|
cy.get('#id_username').should('have.value', admin.username);
|
|
|
|
cy.get('#id_password').type(admin.password);
|
|
|
|
cy.get('#id_password').should('have.value', admin.password);
|
|
|
|
cy.get('.connection-btn').click();
|
2020-07-08 13:41:05 +00:00
|
|
|
cy.location('pathname').should('include', '/authorize');
|
2020-07-03 17:25:23 +00:00
|
|
|
cy.get('.accept-button').click();
|
2020-07-08 13:41:05 +00:00
|
|
|
cy.location().should(location => {
|
|
|
|
expect(location.pathname).to.eq('/');
|
2020-07-03 17:25:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('userLogin', () => {
|
|
|
|
cy.visit('/');
|
|
|
|
cy.location().should((loc) => {
|
|
|
|
expect(loc.pathname).to.eq('/auth/login/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('encodeUrl', url => {
|
|
|
|
const encodeIdReplacement = [
|
|
|
|
['~', '~~'],
|
|
|
|
['.', '~!'],
|
|
|
|
[':', '~@'],
|
|
|
|
['/', '~_'],
|
|
|
|
];
|
|
|
|
encodeIdReplacement.forEach(([char, repl]) => {
|
|
|
|
url = url.split(char).join(repl);
|
|
|
|
});
|
|
|
|
return url;
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('randomNum', () => {
|
|
|
|
return Math.floor(1000 + Math.random() * 9000);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('nextYear', increment => {
|
|
|
|
return new Date().getFullYear() + ( increment || 1 );
|
|
|
|
});
|