refactor: 💡 Create generateScreenshotPath as test helper

Create generateScreenshotPath as test helper
This commit is contained in:
Carlos Alcaide Corvo committed 2021-10-15 09:34:18 -07:00
1 parent e0cee85ad4
commit fe48e0eba2
3 files changed
+37 -29

No files matched your search

+12 -13
View File
@@ -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,
});
});
+7 -16
View File
@@ -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,
});
+18
View File
@@ -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);
};