Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change Login, Logout, Stop and delete workspace tests to be hooks (suileSetup, suiteTeardown) #22636

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/e2e/configs/sh-scripts/runFunctionalTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ initTestValues() {

export TEST_ENVIRONMENT="$OCP_INFRA $MOCHA_DIRECTORY $OCP_VERSION"
export DELETE_WORKSPACE_ON_FAILED_TEST=${DELETE_WORKSPACE_ON_FAILED_TEST:-'false'}
export DELETE_ALL_WORKSPACES_ON_RUN_FINISH=${DELETE_ALL_WORKSPACES_ON_RUN_FINISH:-'true'}
export DELETE_SCREENCAST_IF_TEST_PASS=${DELETE_SCREENCAST_IF_TEST_PASS:-'true'}
export NODE_TLS_REJECT_UNAUTHORIZED=${NODE_TLS_REJECT_UNAUTHORIZED:-'0'}
export TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=${TS_OCP_LOGIN_PAGE_PROVIDER_TITLE:-'htpasswd'}
Expand All @@ -77,9 +78,11 @@ initTestValues() {
export MOCHA_BAIL=${MOCHA_BAIL:-'false'}
export MOCHA_RETRIES=${MOCHA_RETRIES:-'1'}


echo "TS_SELENIUM_BASE_URL=${TS_SELENIUM_BASE_URL}"
echo "TEST_ENVIRONMENT=${TEST_ENVIRONMENT}"
echo "DELETE_WORKSPACE_ON_FAILED_TEST=${DELETE_WORKSPACE_ON_FAILED_TEST}"
echo "DELETE_ALL_WORKSPACES_ON_RUN_FINISH=${DELETE_ALL_WORKSPACES_ON_RUN_FINISH}"
echo "DELETE_SCREENCAST_IF_TEST_PASS=${DELETE_SCREENCAST_IF_TEST_PASS}"
echo "NODE_TLS_REJECT_UNAUTHORIZED=${NODE_TLS_REJECT_UNAUTHORIZED}"
echo "TS_OCP_LOGIN_PAGE_PROVIDER_TITLE=${TS_OCP_LOGIN_PAGE_PROVIDER_TITLE}"
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/constants/BASE_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum Platform {
}

export const BASE_TEST_CONSTANTS: {
DELETE_ALL_WORKSPACES_ON_RUN_FINISH: boolean;
OCP_INFRA: string;
DELETE_WORKSPACE_ON_FAILED_TEST: boolean;
IS_CLUSTER_DISCONNECTED: () => boolean;
Expand Down Expand Up @@ -125,6 +126,11 @@ export const BASE_TEST_CONSTANTS: {
*/
DELETE_WORKSPACE_ON_FAILED_TEST: process.env.DELETE_WORKSPACE_ON_FAILED_TEST === 'true',

/**
* stop and remove all workspaces on test run finish
*/
DELETE_ALL_WORKSPACES_ON_RUN_FINISH: process.env.DELETE_WORKSPACE_ON_FAILED_TEST === 'true',

/**
* constant, which prolong timeout constants for local debug.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class WorkspaceDetails {

await this.clickOnOpenButton(timeout);
await this.testProjectAndFileCheCode.waitWorkspaceReadinessForCheCodeEditor();
this.testWorkspaceUtil.waitWorkspaceStatus(namespace, workspaceName, WorkspaceStatus.STARTING);
await this.testWorkspaceUtil.waitWorkspaceStatus(workspaceName, WorkspaceStatus.STARTING);
}

async waitTabsPresence(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Expand Down
31 changes: 26 additions & 5 deletions tests/e2e/specs/MochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ import { decorate, injectable, unmanaged } from 'inversify';
import { Main } from '@eclipse-che/che-devworkspace-generator/lib/main';
import { LocatorLoader } from 'monaco-page-objects/out/locators/loader';
import { REPORTER_CONSTANTS } from '../constants/REPORTER_CONSTANTS';
import { WorkspaceHandlingTests } from '../tests-library/WorkspaceHandlingTests';

const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
let latestWorkspace: string = '';
export let rpApi: any = undefined;

export function registerRunningWorkspace(workspaceName: string): void {
workspaceName !== '' ? Logger.debug(`with workspaceName:${workspaceName}`) : Logger.debug('delete workspace name');
workspaceName !== ''
? Logger.debug(`with workspaceName:${workspaceName}`)
: ((): void => {
Logger.debug('delete workspace name');
WorkspaceHandlingTests.clearWorkspaceName();
})();

latestWorkspace = workspaceName;
}
Expand Down Expand Up @@ -108,18 +114,33 @@ exports.mochaHooks = {
}
},
// stop and remove running workspace
function deleteWorkspaceOnFailedTest(this: Mocha.Context): void {
async function deleteWorkspaceOnFailedTest(this: Mocha.Context): Promise<void> {
if (this.currentTest?.state === 'failed') {
if (BASE_TEST_CONSTANTS.DELETE_WORKSPACE_ON_FAILED_TEST) {
Logger.info('Property DELETE_WORKSPACE_ON_FAILED_TEST is true - trying to stop and delete running workspace with API.');
if (BASE_TEST_CONSTANTS.DELETE_WORKSPACE_ON_FAILED_TEST && CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) {
Logger.trace(
'Property DELETE_WORKSPACE_ON_FAILED_TEST is true - trying to stop and delete running workspace with API.'
);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
testWorkspaceUtil.stopAndDeleteWorkspaceByName(latestWorkspace);
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(latestWorkspace);
}
}
}
],
afterAll: [
// stop and remove running workspace
async function deleteAllWorkspacesOnFinish(): Promise<void> {
try {
if (BASE_TEST_CONSTANTS.DELETE_ALL_WORKSPACES_ON_RUN_FINISH && CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) {
Logger.trace(
'Property DELETE_WORKSPACE_ON_FAILED_TEST is true - trying to stop and delete all running workspace after test run with API.'
);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
await testWorkspaceUtil.stopAndDeleteAllRunningWorkspaces();
}
} catch (e) {
Logger.trace('Running workspaces not found');
}
},
async function stopTheDriver(): Promise<void> {
if (!BASE_TEST_CONSTANTS.TS_DEBUG_MODE && CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) {
// ensure that fired events done
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/specs/SmokeTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ suite(`The SmokeTest userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, functio
FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || 'https://github.com/che-incubator/quarkus-api-example.git';
let projectSection: ViewSection;
suite(`Create workspace from factory:${factoryUrl}`, function (): void {
loginTests.loginIntoChe();
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});
test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl);
});
Expand All @@ -54,13 +56,15 @@ suite(`The SmokeTest userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, functio
'Project files were not imported'
).not.undefined;
});
test('Stop the workspace', async function (): Promise<void> {
test('Stop the workspace by UI', async function (): Promise<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await browserTabsUtil.closeAllTabsExceptCurrent();
});
test('Delete the workspace', async function (): Promise<void> {
test('Delete the workspace by UI', async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});
loginTests.logoutFromChe();
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});
});
11 changes: 8 additions & 3 deletions tests/e2e/specs/dashboard-samples/Documentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ suite(`Check links to documentation page in Dashboard ${BASE_TEST_CONSTANTS.TEST
({ webSocketTroubleshooting, workspace, devfile, general, storageTypes } = docs);
});

suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});

test('Check if product.json config contains correct application version', function (): void {
[productVersion, links[1].href, devfile, workspace, general, storageTypes, webSocketTroubleshooting].forEach((e): void => {
expect(e, 'Fetched links not matches with tested product version').contains(testingVersion);
});
});

loginTests.loginIntoChe();

test('Check if documentation section "About" present on Dashboard', async function (): Promise<void> {
await dashboard.openAboutMenu();
});
Expand Down Expand Up @@ -135,7 +137,10 @@ suite(`Check links to documentation page in Dashboard ${BASE_TEST_CONSTANTS.TEST
});
}

loginTests.logoutFromChe();
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
await dashboard.openDashboard();
await browserTabsUtil.closeAllTabsExceptCurrent();
});

suiteTeardown('Delete default DevWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace();
Expand Down
23 changes: 15 additions & 8 deletions tests/e2e/specs/dashboard-samples/EmptyWorkspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
**********************************************************************/
import { e2eContainer } from '../../configs/inversify.config';
import { ActivityBar, ViewControl, Workbench } from 'monaco-page-objects';
import { CLASSES } from '../../configs/inversify.types';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { Logger } from '../../utils/Logger';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { LoginTests } from '../../tests-library/LoginTests';
import { registerRunningWorkspace } from '../MochaHooks';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';

const stackName: string = 'Empty Workspace';

Expand All @@ -25,9 +27,12 @@ suite(`${stackName} test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function ():
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);

loginTests.loginIntoChe();

suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});
test(`Create and open new workspace, stack:${stackName}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspace(stackName);
});
Expand All @@ -53,14 +58,16 @@ suite(`${stackName} test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function ():
}
});

test('Stop the workspace', async function (): Promise<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
await dashboard.openDashboard();
await browserTabsUtil.closeAllTabsExceptCurrent();
});

test('Delete the workspace', async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});

loginTests.logoutFromChe();
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});
22 changes: 15 additions & 7 deletions tests/e2e/specs/dashboard-samples/Quarkus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { ViewSection } from 'monaco-page-objects';
import { registerRunningWorkspace } from '../MochaHooks';
import { LoginTests } from '../../tests-library/LoginTests';
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { expect } from 'chai';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';

const stackName: string = 'Java 11 with Quarkus';

Expand All @@ -26,11 +28,15 @@ suite(`The ${stackName} userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, func
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);

let projectSection: ViewSection;
const projectName: string = 'quarkus-quickstarts';

loginTests.loginIntoChe();
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});

test(`Create and open new workspace, stack:${stackName}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspace(stackName);
Expand Down Expand Up @@ -64,14 +70,16 @@ suite(`The ${stackName} userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, func
).not.undefined;
});

test('Stop the workspace', async function (): Promise<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
await dashboard.openDashboard();
await browserTabsUtil.closeAllTabsExceptCurrent();
});

test('Delete the workspace', async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});

loginTests.logoutFromChe();
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});
22 changes: 15 additions & 7 deletions tests/e2e/specs/dashboard-samples/RecommendedExtensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { registerRunningWorkspace } from '../MochaHooks';
import { LoginTests } from '../../tests-library/LoginTests';
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { Logger } from '../../utils/Logger';
Expand All @@ -34,6 +34,8 @@ import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { PLUGIN_TEST_CONSTANTS } from '../../constants/PLUGIN_TEST_CONSTANTS';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';

const samples: string[] = PLUGIN_TEST_CONSTANTS.TS_SAMPLE_LIST.split(',');

Expand All @@ -46,6 +48,8 @@ for (const sample of samples) {
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader);
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);

let projectSection: ViewSection;
let extensionSection: ExtensionsViewSection;
Expand All @@ -56,7 +60,9 @@ for (const sample of samples) {
recommendations: []
};

loginTests.loginIntoChe();
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});

test(`Create and open new workspace, stack:${sample}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspace(sample);
Expand Down Expand Up @@ -202,15 +208,17 @@ for (const sample of samples) {
}
});

test('Stop the workspace', async function (): Promise<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
await dashboard.openDashboard();
await browserTabsUtil.closeAllTabsExceptCurrent();
});

test('Delete the workspace', async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});

loginTests.logoutFromChe();
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});
}
Loading
Loading