diff --git a/cypress/support/commands.js b/cypress/support/commands.js index b13b2e06b..dedce79e8 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -32,13 +32,14 @@ Cypress.Commands.overwrite("visit", (originalVisit, url, options) => { Cypress.Commands.add( "visitSearch", { prevSubject: false }, - (searchQuery, baseUrl = urls.crkeng) => { + (searchQuery, baseUrl = urls.crkeng, headers = {}) => { Cypress.log({ name: "visitSearch", message: `visiting search page for: ${searchQuery}`, }); return cy.visit(`${baseUrl}/search?q=${encodeURIComponent(searchQuery)}`, { escapeComponents: false, + headers }); } ); @@ -134,6 +135,36 @@ Cypress.Commands.add("login", () => { }); }); +Cypress.Commands.add("user_login", (url) => { + cy.visit(url); + cy.get("[name=csrfmiddlewaretoken]") + .should("exist") + .should("have.attr", "value") + .as("csrfToken"); + cy.get("@csrfToken").then(function (token) { + cy.request({ + method: "POST", + url: url, + form: true, + body: { + username : "test_user", + password : "test", + next: "/", + csrfmiddlewaretoken: token, + }, + headers: { + "X-CSRFTOKEN": token, + }, + followRedirect: true, + }).then((response) => { + expect(response.status).to.eql(200); + cy.getCookies().then(cookies => { + Cypress.env('cookies', cookies) + }) + }); + }); +}); + /** * This function returns the column header visually to the top of a td element * (a column header is a th element with scope=col) diff --git a/scripts/run-cypress b/scripts/run-cypress index baa1f1dc2..6e29411c3 100755 --- a/scripts/run-cypress +++ b/scripts/run-cypress @@ -45,7 +45,7 @@ def main(): # Create the gunaha user! for script in manage_scripts: - with open('./create_gunaha_user') as stdin: + with open( script_dir / 'create_gunaha_user') as stdin: check_call([script, "shell"], env=m_env, stdin=stdin) servers = []