From dbadbff1b9d4b6fee68694e48b69c8f9b00ba0f0 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 22 Oct 2021 08:43:03 -0700 Subject: [PATCH 1/2] Add login test helper. Use the new login test helper in targets test --- ui/desktop/tests/end2end/targets.spec.js | 29 ++++++++---------------- ui/desktop/tests/end2end/test-helpers.js | 29 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index e71211cf1..9bb4d0b31 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -25,33 +25,22 @@ test.afterEach(async () => { electronApp = null; // Not sure we should do this. }); -test.describe('Targets end to end test suite', async () => { +test.describe.only('Targets end to end test suite', async () => { test('Connects to a target', async () => { const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app. + // Override local storage origin await boundaryWindow.evaluate(() => window.localStorage.setItem('desktop:origin', null) ); - const originValue = 'http://localhost:9200'; - const authLoginNameValue = 'admin'; - const authLoginPasswordValue = 'password'; - - // Fill the origin input - await boundaryWindow.waitForSelector('[name=host]'); - await boundaryWindow.fill('[name=host]', originValue); - - // Click the submit button - await boundaryWindow.waitForSelector('button[type="submit"]'); - await helpers.click(boundaryWindow, 'button[type="submit"]'); - - // Fill user & password - await boundaryWindow.fill('[name="identification"]', authLoginNameValue); - await boundaryWindow.fill('[name="password"]', authLoginPasswordValue); - - // Click submit - await boundaryWindow.waitForSelector('button[type="submit"]'); - await helpers.click(boundaryWindow, 'button[type="submit"]'); + // Perform the login + await helpers.login( + boundaryWindow, + 'http://localhost:9200', + 'admin', + 'password' + ); // Check we are in Targets await boundaryWindow.waitForURL('**/#/scopes/global/projects/targets'); diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index ba7e739fd..da35f237e 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -46,9 +46,34 @@ exports.returnExecutablePath = (platform, arch) => { /** * Performs a click with a workarouind due to an error with plain playwright click. * More info about the issue here: https://github.com/microsoft/playwright/issues/1808 - * @param {*} appWindow The current electron window. - * @param {*} selector The DOM element selector. + * @param {object} appWindow The electron window to perform the action. + * @param {string} selector The DOM element selector. */ exports.click = async (appWindow, selector) => { await appWindow.$eval(selector, (element) => element.click()); }; + +/** + * Performs login on the app window provided with the credentials provided. + * @param {object} appWindow The electron window to perform the action. + * @param {string} origin URL origin to set. + * @param {string} username Username to login. + * @param {string} password Password to login. + */ +exports.login = async (appWindow, origin, username, password) => { + // Fill the origin input + await appWindow.waitForSelector('[name=host]'); + await appWindow.fill('[name=host]', origin); + + // Click the set origin submit button + await appWindow.waitForSelector('button[type="submit"]'); + await this.click(appWindow, 'button[type="submit"]'); + + // Fill user & password + await appWindow.fill('[name="identification"]', username); + await appWindow.fill('[name="password"]', password); + + // Click submit + await appWindow.waitForSelector('button[type="submit"]'); + await this.click(appWindow, 'button[type="submit"]'); +}; From fd13808cc95e224d0eac8403c25059665c04784e Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 22 Oct 2021 09:11:10 -0700 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20login=20test?= =?UTF-8?q?=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add login test helper and use such helper in the tests --- .../tests/end2end/authentication.spec.js | 68 ++++++------------- ui/desktop/tests/end2end/targets.spec.js | 15 ++-- 2 files changed, 32 insertions(+), 51 deletions(-) diff --git a/ui/desktop/tests/end2end/authentication.spec.js b/ui/desktop/tests/end2end/authentication.spec.js index 93540c0f7..3ba899d13 100644 --- a/ui/desktop/tests/end2end/authentication.spec.js +++ b/ui/desktop/tests/end2end/authentication.spec.js @@ -4,12 +4,19 @@ const { _electron: electron } = require('playwright'); const helpers = require('./test-helpers'); let electronApp = null; +// Subdirectory within tests/end2end/screenshots where the screenshots of this test suite will be stored. const screenshotsDirectory = 'authentication/'; +// Path where the Boundary Desktop client binary is generated const executablePath = helpers.returnExecutablePath( process.platform, process.arch ); +// Set login variables +const originValue = 'http://localhost:9200'; +const loginUsername = 'admin'; +const loginPassword = 'password'; + test.beforeEach(async () => { electronApp = await electron.launch({ executablePath: executablePath, @@ -34,29 +41,15 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.evaluate(() => window.localStorage.setItem('desktop:origin', null) ); - const originValue = 'http://localhost:9200'; - const authLoginNameValue = 'admin'; - const authLoginPasswordValue = 'password'; - // Fill the origin input - await boundaryWindow.waitForSelector('[name=host]'); - await boundaryWindow.fill('[name=host]', originValue); - // Take screenshot - await boundaryWindow.screenshot({ - path: helpers.generateScreenshotPath( - screenshotsDirectory, - 'fillOrigin' - ), - fullPage: true, - }); + // Perform login + await helpers.login( + boundaryWindow, + originValue, + loginUsername, + loginPassword + ); - // Click the submit button - await boundaryWindow.waitForSelector('button[type="submit"]'); - await helpers.click(boundaryWindow, 'button[type="submit"]'); - - // Fill user & password - await boundaryWindow.fill('[name="identification"]', authLoginNameValue); - await boundaryWindow.fill('[name="password"]', authLoginPasswordValue); // Take screenshot await boundaryWindow.screenshot({ path: helpers.generateScreenshotPath( @@ -126,32 +119,13 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.evaluate(() => window.localStorage.setItem('desktop:origin', null) ); - const originValue = 'http://localhost:9200'; - const authLoginNameValue = 'admin'; - const authLoginPasswordValue = '123456'; - - // Fill the origin input - await boundaryWindow.fill('[name=host]', originValue); - // Take screenshot - await boundaryWindow.screenshot({ - path: helpers.generateScreenshotPath( - screenshotsDirectory, - 'fillOrigin' - ), - fullPage: true, - }); - - // Click the submit button - await boundaryWindow.waitForSelector('button[type="submit"]'); - await helpers.click(boundaryWindow, 'button[type="submit"]'); - - // Fill user & password - await boundaryWindow.fill('[name="identification"]', authLoginNameValue); - await boundaryWindow.fill('[name="password"]', authLoginPasswordValue); - - // Click submit - await boundaryWindow.waitForSelector('button[type="submit"]'); - await helpers.click(boundaryWindow, 'button[type="submit"]'); + // Perform login + await helpers.login( + boundaryWindow, + originValue, + loginUsername, + '123456789' + ); // Wait for the notification await boundaryWindow.waitForSelector('.rose-notification-body'); diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index 9bb4d0b31..3baa15199 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -4,12 +4,19 @@ const { _electron: electron } = require('playwright'); const helpers = require('./test-helpers'); let electronApp = null; +// Subdirectory within tests/end2end/screenshots where the screenshots of this test suite will be stored. const screenshotsDirectory = 'targets/'; +// Path where the Boundary Desktop client binary is generated const executablePath = helpers.returnExecutablePath( process.platform, process.arch ); +// Set login variables +const originValue = 'http://localhost:9200'; +const loginUsername = 'admin'; +const loginPassword = 'password'; + test.beforeEach(async () => { electronApp = await electron.launch({ executablePath: executablePath, @@ -25,7 +32,7 @@ test.afterEach(async () => { electronApp = null; // Not sure we should do this. }); -test.describe.only('Targets end to end test suite', async () => { +test.describe('Targets end to end test suite', async () => { test('Connects to a target', async () => { const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app. @@ -37,9 +44,9 @@ test.describe.only('Targets end to end test suite', async () => { // Perform the login await helpers.login( boundaryWindow, - 'http://localhost:9200', - 'admin', - 'password' + originValue, + loginUsername, + loginPassword ); // Check we are in Targets