Refactor login test to command
This commit is contained in:
parent
4f76d56b19
commit
4abf899222
|
|
@ -3,21 +3,58 @@ describe('The Login Page', () => {
|
||||||
const username = 'test';
|
const username = 'test';
|
||||||
const password = 'test';
|
const password = 'test';
|
||||||
|
|
||||||
cy.visit('/');
|
cy.login(username, password);
|
||||||
|
|
||||||
cy.get('#id_username').type(username);
|
|
||||||
cy.get('#id_password').type(`${password}{enter}`);
|
|
||||||
|
|
||||||
cy.getCookie('sessionid').should('exist');
|
cy.getCookie('sessionid').should('exist');
|
||||||
cy.get('.start-page__title').should('contain', 'skillbox')
|
cy.get('.start-page__title').should('contain', 'skillbox')
|
||||||
});
|
});
|
||||||
it('logs in programmatically without using the UI', () => {
|
// it('logs in programmatically without using the UI', () => {
|
||||||
const username = 'test';
|
// cy.visit('/accounts/login/'); // have to get a csrf token by getting the base page first
|
||||||
const password = 'test';
|
//
|
||||||
|
// const username = 'test';
|
||||||
|
// const password = 'test';
|
||||||
|
//
|
||||||
|
// cy.getCookie('csrftoken').then(token => {
|
||||||
|
// const options = {
|
||||||
|
// url: '/accounts/login/',
|
||||||
|
// method: 'POST',
|
||||||
|
// headers: {
|
||||||
|
// 'X-CSRFToken': token.value,
|
||||||
|
// 'content-type': 'multipart/form-data'
|
||||||
|
// },
|
||||||
|
// from: true,
|
||||||
|
// body: {
|
||||||
|
// username: username,
|
||||||
|
// password: password,
|
||||||
|
// // csrfmiddlewaretoken: token.value
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// cy.request(options);
|
||||||
|
// cy.getCookie('sessionid').should('exist');
|
||||||
|
// cy.visit('/');
|
||||||
|
//
|
||||||
|
// cy.get('.start-page__title').should('contain', 'skillbox')
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // cy.visit('/');
|
||||||
|
// // cy.getCookie('csrftoken')
|
||||||
|
// // .then((csrftoken) => {
|
||||||
|
// // const response = cy.request({
|
||||||
|
// // method: 'POST',
|
||||||
|
// // url: '/login/',
|
||||||
|
// // form: true,
|
||||||
|
// // body: {
|
||||||
|
// // identification: username,
|
||||||
|
// // password: password,
|
||||||
|
// // csrfmiddlewaretoken: csrftoken.value
|
||||||
|
// // }
|
||||||
|
// // });
|
||||||
|
// // });
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
|
||||||
cy.request('POST', '/login', {
|
|
||||||
username,
|
// })
|
||||||
password
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,11 @@
|
||||||
//
|
//
|
||||||
// -- This is will overwrite an existing command --
|
// -- This is will overwrite an existing command --
|
||||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||||
|
|
||||||
|
Cypress.Commands.add("login", (username, password) => {
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.get('#id_username').type(username);
|
||||||
|
cy.get('#id_password').type(`${password}{enter}`);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue