From 82c7638277e3dd2975f0543e3b9561425c7c8185 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 7 Oct 2021 13:28:51 -0700 Subject: [PATCH 1/4] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20connect=20to?= =?UTF-8?q?=20target=20e2e=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First iteration of connect to target end to end test --- ui/desktop/tests/end2end/targets.spec.js | 128 +++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 ui/desktop/tests/end2end/targets.spec.js diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js new file mode 100644 index 000000000..4e05aeed2 --- /dev/null +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -0,0 +1,128 @@ +/* eslint-disable no-undef */ +const { test, expect } = require('@playwright/test'); +const { _electron: electron } = require('playwright'); +const path = require('path'); + +let electronApp = null; +const returnScreenshotPath = (fileName) => { + const screenshotPath = 'tests/end2end/screenshots/targets/'; + const screenshotFormat = '.png'; + return path.join(screenshotPath, fileName).concat(screenshotFormat); +}; + +test.beforeEach(async () => { + electronApp = await electron.launch({ + executablePath: + 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary', + env: { + NODE_ENV: 'test', + BYPASS_APP_UPDATER: true, + }, + }); +}); + +test.afterEach(async () => { + electronApp.close(); + electronApp = null; // Not sure we should do this. +}); + +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. + // 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('.ember-text-field'); + await boundaryWindow.fill('.ember-text-field', originValue); + + // Click the submit button + // Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround. + // More info about it here: https://github.com/microsoft/playwright/issues/1808 + await boundaryWindow.waitForSelector('button[type="submit"]'); + await boundaryWindow.$eval('button[type="submit"]', (element) => + element.click() + ); + // Fill user & password + await boundaryWindow.fill('[name="identification"]', authLoginNameValue); + await boundaryWindow.fill('[name="password"]', authLoginPasswordValue); + + // Click submit + await boundaryWindow.waitForSelector('button[type="submit"]'); + await boundaryWindow.$eval('button[type="submit"]', (element) => + element.click() + ); + // Check we are in Targets + await boundaryWindow.waitForSelector('h2 >> text=Targets'); + expect(await boundaryWindow.innerText('h2 >> text=Targets')).toEqual( + 'Targets ' + ); + + // Click connect to a target + await boundaryWindow.waitForSelector('table.rose-table'); + await boundaryWindow.$eval( + 'table.rose-table >> tbody >> tr >> nth=0 >> button >> text=Connect', + (element) => element.click() + ); + + // The target popup opens + await boundaryWindow.waitForSelector('section.dialog-detail'); + // Take screenshot + await boundaryWindow.screenshot({ + path: returnScreenshotPath('targetConnectionDetails'), + fullPage: true, + }); + // Click copyable in popup + // TODO: read clipboard value. Running into issues reading clipboard, so will take a shortcut for now + await boundaryWindow.$eval( + 'section.dialog-detail >> div.rose-dialog-body >> button', + (element) => element.click() + ); + // Temporary: persist proxy from target + const persistedProxy = await boundaryWindow.innerText( + 'section.dialog-detail >> div.rose-dialog-body >> span.copyable-content' + ); + + // Click close popup + await boundaryWindow.$eval( + 'section.dialog-detail >> footer >> button', + (element) => element.click() + ); + + // On left nav menu, click Sessions + await boundaryWindow.waitForSelector('section.rose-layout-global >> aside'); + await boundaryWindow.$eval( + 'section.rose-layout-global >> aside >> nav >> a >> text=Sessions', + (element) => element.click() + ); + + // Take screenshot + await boundaryWindow.screenshot({ + path: returnScreenshotPath('sessions'), + fullPage: true, + }); + + // Check the right session has status pending. + await boundaryWindow.waitForSelector( + 'main >> div.rose-layout-page-body >> table.rose-table' + ); + // Select Proxy + const currentProxy = await boundaryWindow.innerText( + 'div.rose-layout-page-body >> table >> tbody >> tr >> nth=0 >> td >> nth=1 >> .copyable-content' + ); + const currentStatus = await boundaryWindow.innerText( + 'div.rose-layout-page-body >> table >> tbody >> tr >> nth=0 >> td >> nth=3 >> .rose-badge-body' + ); + + expect(await persistedProxy).toEqual(await currentProxy); + expect(await currentStatus).toEqual('pending'); + // TODO: before closing the app we should terminate sessions. + // TODO: add test to check if sessions are not terminated we promp the confirmation dialog + }); +}); From 9ad765327dfb65a62304a3b6877fab9bbb70540b Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 13 Oct 2021 07:50:54 -0700 Subject: [PATCH 2/4] Rename function --- ui/desktop/tests/end2end/targets.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index 4e05aeed2..340a94d33 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -4,7 +4,7 @@ const { _electron: electron } = require('playwright'); const path = require('path'); let electronApp = null; -const returnScreenshotPath = (fileName) => { +const generateScreenshotPath = (fileName) => { const screenshotPath = 'tests/end2end/screenshots/targets/'; const screenshotFormat = '.png'; return path.join(screenshotPath, fileName).concat(screenshotFormat); @@ -75,7 +75,7 @@ test.describe('Targets end to end test suite', async () => { await boundaryWindow.waitForSelector('section.dialog-detail'); // Take screenshot await boundaryWindow.screenshot({ - path: returnScreenshotPath('targetConnectionDetails'), + path: generateScreenshotPath('targetConnectionDetails'), fullPage: true, }); // Click copyable in popup @@ -104,7 +104,7 @@ test.describe('Targets end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ - path: returnScreenshotPath('sessions'), + path: generateScreenshotPath('sessions'), fullPage: true, }); From 960e91c8e545f3fdd484002aa85f14216d142445 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 14 Oct 2021 10:35:28 -0700 Subject: [PATCH 3/4] Change the way we check we are in targets section. Now we check the url rather than the h2 title --- ui/desktop/tests/end2end/authentication.spec.js | 11 ++++++----- ui/desktop/tests/end2end/targets.spec.js | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ui/desktop/tests/end2end/authentication.spec.js b/ui/desktop/tests/end2end/authentication.spec.js index 553a4b5cd..9986b0773 100644 --- a/ui/desktop/tests/end2end/authentication.spec.js +++ b/ui/desktop/tests/end2end/authentication.spec.js @@ -10,7 +10,7 @@ const generateScreenshotPath = (fileName) => { return path.join(screenshotPath, fileName).concat(screenshotFormat); }; -// Todo: move this function to a test helpers file so it could be used by other tests. +// TODO: move this function to a test helpers file so it could be used by other tests. // Returns the executable path for the Boundary binary the test suite will run. const returnExecutablePath = (platform, arch) => { try { @@ -91,11 +91,12 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.$eval('button[type="submit"]', (element) => element.click() ); + // Check we are in Targets - await boundaryWindow.waitForSelector('h2 >> text=Targets'); - expect(await boundaryWindow.innerText('h2 >> text=Targets')).toEqual( - 'Targets ' - ); + await boundaryWindow.waitForURL('**/#/scopes/global/projects/targets'); + const windowUrl = new URL(await boundaryWindow.url()); + expect(windowUrl.hash).toEqual('#/scopes/global/projects/targets'); + // Take screenshot await boundaryWindow.screenshot({ path: generateScreenshotPath('afterLogin'), diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index 340a94d33..56411e15c 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -58,11 +58,11 @@ test.describe('Targets end to end test suite', async () => { await boundaryWindow.$eval('button[type="submit"]', (element) => element.click() ); + // Check we are in Targets - await boundaryWindow.waitForSelector('h2 >> text=Targets'); - expect(await boundaryWindow.innerText('h2 >> text=Targets')).toEqual( - 'Targets ' - ); + await boundaryWindow.waitForURL('**/#/scopes/global/projects/targets'); + const windowUrl = new URL(await boundaryWindow.url()); + expect(windowUrl.hash).toEqual('#/scopes/global/projects/targets'); // Click connect to a target await boundaryWindow.waitForSelector('table.rose-table'); From 20172626cb9de556690f244ae3b4536f64c0352b Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 15 Oct 2021 08:54:08 -0700 Subject: [PATCH 4/4] Change selector for origin input field --- ui/desktop/tests/end2end/authentication.spec.js | 10 +++++----- ui/desktop/tests/end2end/targets.spec.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/desktop/tests/end2end/authentication.spec.js b/ui/desktop/tests/end2end/authentication.spec.js index 9986b0773..f3547656b 100644 --- a/ui/desktop/tests/end2end/authentication.spec.js +++ b/ui/desktop/tests/end2end/authentication.spec.js @@ -62,8 +62,8 @@ test.describe('Authentication end to end test suite', async () => { const authLoginPasswordValue = 'password'; // Fill the origin input - await boundaryWindow.waitForSelector('.ember-text-field'); - await boundaryWindow.fill('.ember-text-field', originValue); + await boundaryWindow.waitForSelector('[name=host]'); + await boundaryWindow.fill('[name=host]', originValue); // Take screenshot await boundaryWindow.screenshot({ path: generateScreenshotPath('fillOrigin'), @@ -147,7 +147,7 @@ test.describe('Authentication end to end test suite', async () => { const authLoginPasswordValue = '123456'; // Fill the origin input - await boundaryWindow.fill('.ember-text-field', originValue); + await boundaryWindow.fill('[name=host]', originValue); // Take screenshot await boundaryWindow.screenshot({ path: generateScreenshotPath('fillOrigin'), @@ -206,8 +206,8 @@ test.describe('Authentication end to end test suite', async () => { const originValue = 'http://localhost:9200'; // Fill the origin input - await boundaryWindow.waitForSelector('.ember-text-field'); - await boundaryWindow.fill('.ember-text-field', originValue); + await boundaryWindow.waitForSelector('[name=host]'); + await boundaryWindow.fill('[name=host]', originValue); // Click the submit button // Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround. diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index 56411e15c..eb048c90c 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -39,8 +39,8 @@ test.describe('Targets end to end test suite', async () => { const authLoginPasswordValue = 'password'; // Fill the origin input - await boundaryWindow.waitForSelector('.ember-text-field'); - await boundaryWindow.fill('.ember-text-field', originValue); + await boundaryWindow.waitForSelector('[name=host]'); + await boundaryWindow.fill('[name=host]', originValue); // Click the submit button // Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.