Created
June 22, 2020 09:56
-
-
Save roma-glushko/25771f237ed03617a0cee38cb2bd5782 to your computer and use it in GitHub Desktop.
Revisions
-
Roman Glushko created this gist
Jun 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ Cypress.Commands.add("loginAsCustomer", (username, password) => { cy.request('/customer/account/login') .its('body') .then((body) => { const $html = Cypress.$(body) const formKey = $html.find('input[name="form_key"]').val() cy.request({ method: 'POST', url: '/customer/account/loginPost', failOnStatusCode: false, // dont fail so we can make assertions form: true, // we are submitting a regular form body body: { login: { username, password, }, form_key: formKey, // insert this as part of form body }, }) .then((resp) => { expect(resp.status).to.eq(200) resp.headers['set-cookie'].forEach(cookie => { const [nameValueString, ] = cookie.split(';') const [cookieName, cookieValue] = nameValueString.split('=') cy.setCookie(cookieName, cookieValue); }) }); }) })