From 5b226edf769386fdf96d9d681b8fa4fe74bac455 Mon Sep 17 00:00:00 2001 From: Jan-Gerke Salomon Date: Thu, 19 Nov 2020 12:32:35 +0100 Subject: [PATCH] feat(login): add command to fill login form --- .../src/commands/fillAndSubmitLoginForm.js | 19 +++++++++++++++++++ packages/cypress-commands/src/index.js | 1 + 2 files changed, 20 insertions(+) create mode 100644 packages/cypress-commands/src/commands/fillAndSubmitLoginForm.js 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'