1 // ***********************************************
2 // This example commands.js shows you how to
3 // create various custom commands and overwrite
6 // For more comprehensive examples of custom
7 // commands please read more here:
8 // https://on.cypress.io/custom-commands
9 // ***********************************************
12 // -- This is a parent command --
13 // Cypress.Commands.add('login', (email, password) => { ... })
16 // -- This is a child command --
17 // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
20 // -- This is a dual command --
21 // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
24 // -- This will overwrite an existing command --
25 // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27 function get_fallback_login_value(param) {
29 var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS';
31 return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var);
34 Cypress.Commands.add('login', (username, password) => {
35 var user = typeof username === 'undefined' ? get_fallback_login_value('username') : username;
36 var pass = typeof password === 'undefined' ? get_fallback_login_value('password') : password;
37 cy.visit('/cgi-bin/koha/mainpage.pl?logout.x=1')
38 cy.get("#userid").type(user)
39 cy.get("#password").type(pass)
40 cy.get("#submit-button").click()