From c5a88e3a92ac069127d6b7a7caf15de2a5600d05 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 10 Jul 2025 22:05:57 +0200 Subject: [PATCH] Bug 40346: Introduce loginOpac and visitOpac - Cypress To be able to test the OPAC interface we need to add those 2 new commands --- cypress.config.ts | 9 +++++---- t/cypress/support/e2e.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index fd17efc7857..fed6e7b97b4 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -15,9 +15,10 @@ export default defineConfig({ baseUrl: "http://localhost:8081", specPattern: "t/cypress/integration/**/*.*", supportFile: "t/cypress/support/e2e.js", - }, - env: { - apiUsername: "koha", - apiPassword: "koha", + env: { + opacBaseUrl: process.env.KOHA_OPAC_URL || "http://localhost:8080", + apiUsername: "koha", + apiPassword: "koha", + }, }, }); diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index 40265d607bf..ae58126313f 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -32,6 +32,10 @@ function get_fallback_login_value(param) { : Cypress.env(env_var); } +Cypress.Commands.add("visitOpac", path => { + cy.visit(Cypress.env("opacBaseUrl") + path); +}); + Cypress.Commands.add("login", (username, password) => { var user = typeof username === "undefined" @@ -47,6 +51,21 @@ Cypress.Commands.add("login", (username, password) => { cy.get("#submit-button").click(); }); +Cypress.Commands.add("loginOpac", (username, password) => { + var user = + typeof username === "undefined" + ? get_fallback_login_value("username") + : username; + var pass = + typeof password === "undefined" + ? get_fallback_login_value("password") + : password; + cy.visitOpac("/cgi-bin/koha/opac-main.pl?logout.x=1"); + cy.get("#userid").type(user); + cy.get("#password").type(pass); + cy.get("#auth .action").contains("Log in").click(); +}); + Cypress.Commands.add("left_menu_active_item_is", label => { cy.get(".sidebar_menu a.current:not(.disabled)") .should("have.length", 1) -- 2.34.1