diff --git a/packages/cypress-commands/src/commands/fillAndSubmitLoginForm.js b/packages/cypress-commands/src/commands/fillAndSubmitLoginForm.js new file mode 100644 index 00000000..ab455e4e --- /dev/null +++ b/packages/cypress-commands/src/commands/fillAndSubmitLoginForm.js @@ -0,0 +1,19 @@ +/** + * @param {Object} args + * @param {string} args.userName + * @param {string} args.password + * @param {string} [args.loginUrl] + * When not provided, the server field will be ignored. + * If the server is already set through an env var, + * then not providing this property will produce the expected result + * + * @returns {void} + */ +export const fillAndSubmitLoginForm = ({ loginUrl, userName, password }) => { + loginUrl && cy.get('#server').type(loginUrl) + cy.get('#j_username').type(userName) + cy.get('#j_password').type(password) + cy.get('{loginsubmit}', { prefix: 'dhis2-adapter' }).click() +} + +Cypress.Commands.add('fillAndSubmitLoginForm', fillAndSubmitLoginForm) diff --git a/packages/cypress-commands/src/index.js b/packages/cypress-commands/src/index.js index b2615628..64e836ed 100644 --- a/packages/cypress-commands/src/index.js +++ b/packages/cypress-commands/src/index.js @@ -1,4 +1,5 @@ // will automatically create the commands +import './commands/fillAndSubmitLoginForm' import './commands/find' import './commands/get' import './commands/login'