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/7] =?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/7] 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/7] 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/7] 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. From e0cee85ad4d5cfe40cfaae2a711601ca777b61fa Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 7 Oct 2021 13:28:51 -0700 Subject: [PATCH 5/7] =?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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index eb048c90c..12ca2779b 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -75,7 +75,11 @@ test.describe('Targets end to end test suite', async () => { await boundaryWindow.waitForSelector('section.dialog-detail'); // Take screenshot await boundaryWindow.screenshot({ +<<<<<<< HEAD path: generateScreenshotPath('targetConnectionDetails'), +======= + path: returnScreenshotPath('targetConnectionDetails'), +>>>>>>> 5f79634d (test: 💍 Add connect to target e2e test) fullPage: true, }); // Click copyable in popup @@ -104,7 +108,11 @@ test.describe('Targets end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ +<<<<<<< HEAD path: generateScreenshotPath('sessions'), +======= + path: returnScreenshotPath('sessions'), +>>>>>>> 5f79634d (test: 💍 Add connect to target e2e test) fullPage: true, }); From fe48e0eba2d854bc11a81e4be7f189489e8649e3 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 13 Oct 2021 14:07:37 -0700 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Create=20generat?= =?UTF-8?q?eScreenshotPath=20as=20test=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create generateScreenshotPath as test helper --- .../tests/end2end/authentication.spec.js | 25 +++++++++---------- ui/desktop/tests/end2end/targets.spec.js | 23 ++++++----------- ui/desktop/tests/end2end/test-helpers.js | 18 +++++++++++++ 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 ui/desktop/tests/end2end/test-helpers.js diff --git a/ui/desktop/tests/end2end/authentication.spec.js b/ui/desktop/tests/end2end/authentication.spec.js index f3547656b..c7a02fbcd 100644 --- a/ui/desktop/tests/end2end/authentication.spec.js +++ b/ui/desktop/tests/end2end/authentication.spec.js @@ -1,14 +1,10 @@ /* eslint-disable no-undef */ const { test, expect } = require('@playwright/test'); const { _electron: electron } = require('playwright'); -const path = require('path'); +const { generateScreenshotPath } = require('./test-helpers'); let electronApp = null; -const generateScreenshotPath = (fileName) => { - const screenshotPath = 'tests/end2end/screenshots/authentication/'; - const screenshotFormat = '.png'; - return path.join(screenshotPath, fileName).concat(screenshotFormat); -}; +const screenshotsDirectory = 'authentication/'; // 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. @@ -66,7 +62,7 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.fill('[name=host]', originValue); // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('fillOrigin'), + path: generateScreenshotPath(screenshotsDirectory, 'fillOrigin'), fullPage: true, }); @@ -82,7 +78,7 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.fill('[name="password"]', authLoginPasswordValue); // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('fillUserPassword'), + path: generateScreenshotPath(screenshotsDirectory, 'fillUserPassword'), fullPage: true, }); @@ -99,7 +95,7 @@ test.describe('Authentication end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('afterLogin'), + path: generateScreenshotPath(screenshotsDirectory, 'afterLogin'), fullPage: true, }); @@ -114,7 +110,7 @@ test.describe('Authentication end to end test suite', async () => { expect(await boundaryWindow.isVisible('details')); // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('userDropdown'), + path: generateScreenshotPath(screenshotsDirectory, 'userDropdown'), fullPage: true, }); @@ -131,7 +127,7 @@ test.describe('Authentication end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('afterLogout'), + path: generateScreenshotPath(screenshotsDirectory, 'afterLogout'), fullPage: true, }); }); @@ -150,7 +146,7 @@ test.describe('Authentication end to end test suite', async () => { await boundaryWindow.fill('[name=host]', originValue); // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('fillOrigin'), + path: generateScreenshotPath(screenshotsDirectory, 'fillOrigin'), fullPage: true, }); @@ -180,7 +176,10 @@ test.describe('Authentication end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ - path: generateScreenshotPath('notificationFailed'), + path: generateScreenshotPath( + screenshotsDirectory, + 'notificationFailed' + ), fullPage: true, }); }); diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index 12ca2779b..d30084031 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -1,14 +1,10 @@ /* eslint-disable no-undef */ const { test, expect } = require('@playwright/test'); const { _electron: electron } = require('playwright'); -const path = require('path'); +const { generateScreenshotPath } = require('./test-helpers'); let electronApp = null; -const generateScreenshotPath = (fileName) => { - const screenshotPath = 'tests/end2end/screenshots/targets/'; - const screenshotFormat = '.png'; - return path.join(screenshotPath, fileName).concat(screenshotFormat); -}; +const screenshotsDirectory = 'targets/'; test.beforeEach(async () => { electronApp = await electron.launch({ @@ -75,11 +71,10 @@ test.describe('Targets end to end test suite', async () => { await boundaryWindow.waitForSelector('section.dialog-detail'); // Take screenshot await boundaryWindow.screenshot({ -<<<<<<< HEAD - path: generateScreenshotPath('targetConnectionDetails'), -======= - path: returnScreenshotPath('targetConnectionDetails'), ->>>>>>> 5f79634d (test: 💍 Add connect to target e2e test) + path: generateScreenshotPath( + screenshotsDirectory, + 'targetConnectionDetails' + ), fullPage: true, }); // Click copyable in popup @@ -108,11 +103,7 @@ test.describe('Targets end to end test suite', async () => { // Take screenshot await boundaryWindow.screenshot({ -<<<<<<< HEAD - path: generateScreenshotPath('sessions'), -======= - path: returnScreenshotPath('sessions'), ->>>>>>> 5f79634d (test: 💍 Add connect to target e2e test) + path: generateScreenshotPath(screenshotsDirectory, 'sessions'), fullPage: true, }); diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js new file mode 100644 index 000000000..2b0de5c8c --- /dev/null +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -0,0 +1,18 @@ +/* eslint-disable no-undef */ +const path = require('path'); + +/** + * + * @param {string} screenshotTestDirectory screenshot directory for the specific test suite + * @param {string} fileName The file name. + * @returns A full path where to save the screenshot. + */ +exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { + const screenshotFormat = '.png'; + const screenshotsRootPath = path.join(__dirname, '/screenshots/'); + const screenshotPath = path.join( + screenshotsRootPath, + screenshotTestDirectory + ); + return path.join(screenshotPath, fileName).concat(screenshotFormat); +}; From af2e111dcd8172b2b1e85b0613015dc8bffdf66e Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 15 Oct 2021 09:35:28 -0700 Subject: [PATCH 7/7] Delete trailing slashes from path --- ui/desktop/tests/end2end/test-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index 2b0de5c8c..8c43b84f4 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -9,7 +9,7 @@ const path = require('path'); */ exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { const screenshotFormat = '.png'; - const screenshotsRootPath = path.join(__dirname, '/screenshots/'); + const screenshotsRootPath = path.join(__dirname, 'screenshots'); const screenshotPath = path.join( screenshotsRootPath, screenshotTestDirectory