Bug 33606: Add a erm/config route to retrieve the ERM config needed for the Vue app
[koha.git] / t / cypress / support / commands.js
1 // ***********************************************
2 // This example commands.js shows you how to
3 // create various custom commands and overwrite
4 // existing commands.
5 //
6 // For more comprehensive examples of custom
7 // commands please read more here:
8 // https://on.cypress.io/custom-commands
9 // ***********************************************
10 //
11 //
12 // -- This is a parent command --
13 // Cypress.Commands.add('login', (email, password) => { ... })
14 //
15 //
16 // -- This is a child command --
17 // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18 //
19 //
20 // -- This is a dual command --
21 // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22 //
23 //
24 // -- This will overwrite an existing command --
25 // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26
27 function get_fallback_login_value(param) {
28
29     var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS';
30
31     return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var);
32 }
33
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()
41 })