Bug 32898: Avoid hardcoding user/pass in tests

This patch makes the authentication parameters be configurable through
env. Before this, it was hardcoded to koha/koha, which only works if the
ktd defaults haven't been tweaked.

If no env is defined, it fallsback to koha/koha.

In order to pass the ktd configured params, the tests need to be run
like:

$ yarn cypress run --env KOHA_USER=$KOHA_USER,KOHA_PASS=$KOHA_PASS

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2023-02-20 11:07:44 -03:00
parent a36f3ed7fe
commit 53bebb413a
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
5 changed files with 16 additions and 8 deletions

View File

@ -123,7 +123,7 @@ describe("Agreement CRUD operations", () => {
});
beforeEach(() => {
cy.login("koha", "koha");
cy.login();
cy.title().should("eq", "Koha staff interface");
});

View File

@ -39,7 +39,7 @@ describe("License CRUD operations", () => {
});
beforeEach(() => {
cy.login("koha", "koha");
cy.login();
cy.title().should("eq", "Koha staff interface");
});

View File

@ -30,7 +30,7 @@ describe("Package CRUD operations", () => {
});
beforeEach(() => {
cy.login("koha", "koha");
cy.login();
cy.title().should("eq", "Koha staff interface");
});

View File

@ -73,7 +73,7 @@ describe("Title CRUD operations", () => {
});
beforeEach(() => {
cy.login("koha", "koha");
cy.login();
cy.title().should("eq", "Koha staff interface");
});

View File

@ -24,11 +24,19 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
function get_fallback_login_value(param) {
var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS';
return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var);
}
Cypress.Commands.add('login', (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.visit('/cgi-bin/koha/mainpage.pl?logout.x=1')
cy.get("#userid").type(username)
cy.get("#password").type(password)
cy.get("#userid").type(user)
cy.get("#password").type(pass)
cy.get("#submit-button").click()
})
@ -49,7 +57,7 @@ Cypress.Commands.add('set_ERM_sys_pref_value', (enable) => {
})
Cypress.Commands.add('fetch_initial_ERM_sys_pref_value', () => {
cy.login("koha", "koha");
cy.login();
cy.visit('/cgi-bin/koha/admin/admin-home.pl')
cy.get("h4").contains("Global system preferences").click();
cy.get("a[title^=E-resource]").contains("E-resource management").click();
@ -59,6 +67,6 @@ Cypress.Commands.add('fetch_initial_ERM_sys_pref_value', () => {
})
Cypress.Commands.add('reset_initial_ERM_sys_pref_value', () => {
cy.login("koha", "koha");
cy.login();
cy.set_ERM_sys_pref_value(Cypress.env("initial_ERM_Module_sys_pref_value"));
})