From 9a6852ebc822a21d8864853f5881de6148dcc2fe Mon Sep 17 00:00:00 2001 From: Aleksandr Shmaraiev Date: Thu, 9 Jan 2025 18:30:52 +0200 Subject: [PATCH] Update 'Factory' e2e test --- tests/e2e/constants/BASE_TEST_CONSTANTS.ts | 12 ++++++++ tests/e2e/pageobjects/dashboard/Dashboard.ts | 7 +++++ tests/e2e/specs/factory/Factory.spec.ts | 31 ++++++++++++++------ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts index 900ea1efe0d..5d17308a6d8 100644 --- a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts @@ -15,6 +15,8 @@ export enum Platform { export const BASE_TEST_CONSTANTS: { OCP_INFRA: string; DELETE_WORKSPACE_ON_FAILED_TEST: boolean; + DELETE_WORKSPACE_ON_SUCCESSFUL_TEST: boolean; + IS_RESTART_EXISTING_WORKSPACE: boolean; IS_CLUSTER_DISCONNECTED: () => boolean; IS_PRODUCT_DOCUMENTATION_RELEASED: any; OCP_VERSION: string; @@ -130,6 +132,16 @@ export const BASE_TEST_CONSTANTS: { */ DELETE_WORKSPACE_ON_FAILED_TEST: process.env.DELETE_WORKSPACE_ON_FAILED_TEST === 'true', + /** + * stop and remove workspace if a test is successful. + */ + DELETE_WORKSPACE_ON_SUCCESSFUL_TEST: process.env.DELETE_WORKSPACE_ON_SUCCESSFUL_TEST !== 'false', + + /** + * restart existing workspace. + */ + IS_RESTART_EXISTING_WORKSPACE: process.env.IS_RESTART_EXISTING_WORKSPACE === 'true', + /** * constant, which prolong timeout constants for local debug. */ diff --git a/tests/e2e/pageobjects/dashboard/Dashboard.ts b/tests/e2e/pageobjects/dashboard/Dashboard.ts index 3bd48875b3f..abb4ae990aa 100644 --- a/tests/e2e/pageobjects/dashboard/Dashboard.ts +++ b/tests/e2e/pageobjects/dashboard/Dashboard.ts @@ -39,6 +39,7 @@ export class Dashboard { username: 'username' }; private static readonly CONTINUE_WITH_DEFAULT_DEVFILE_BUTTON: By = By.xpath('//button[text()="Continue with default devfile"]'); + private static readonly OPEN_EXISTING_WORKSPACE_LINK: By = By.xpath('//button[text()="Open the existing workspace"]'); constructor( @inject(CLASSES.DriverHelper) @@ -176,6 +177,12 @@ export class Dashboard { await this.driverHelper.waitAndClick(Dashboard.CREATE_NEW_WORKSPACE_LINK, timeout); } + async clickOpenExistingWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise { + Logger.debug(); + + await this.driverHelper.waitAndClick(Dashboard.OPEN_EXISTING_WORKSPACE_LINK, timeout); + } + async logout(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise { Logger.debug(); diff --git a/tests/e2e/specs/factory/Factory.spec.ts b/tests/e2e/specs/factory/Factory.spec.ts index dd9546f00d9..db45a97edbf 100644 --- a/tests/e2e/specs/factory/Factory.spec.ts +++ b/tests/e2e/specs/factory/Factory.spec.ts @@ -88,6 +88,13 @@ suite( }); } + if (BASE_TEST_CONSTANTS.IS_RESTART_EXISTING_WORKSPACE) { + test('Restart existing workspace', async function (): Promise { + await dashboard.waitExistingWorkspaceFoundAlert(); + await dashboard.clickOpenExistingWorkspaceButton(); + }); + } + test('Obtain workspace name from workspace loader page', async function (): Promise { await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); }); @@ -209,14 +216,20 @@ suite( await browserTabsUtil.closeAllTabsExceptCurrent(); }); - suiteTeardown('Stop and delete the workspace by API', async function (): Promise { - // to avoid a possible creating workspace which is not appeared on Dashboard yet. TODO: implement a better solution. - await driverHelper.wait(30000); - await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); - }); - - suiteTeardown('Unregister running workspace', function (): void { - registerRunningWorkspace(''); - }); + if (BASE_TEST_CONSTANTS.DELETE_WORKSPACE_ON_SUCCESSFUL_TEST) { + suiteTeardown('Stop and delete the workspace by API', async function (): Promise { + // to avoid a possible creating workspace which is not appeared on Dashboard yet. TODO: implement a better solution. + await driverHelper.wait(30000); + await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); + }); + + suiteTeardown('Unregister running workspace', function (): void { + registerRunningWorkspace(''); + }); + } else { + suiteTeardown('Registering the running workspace', function (): void { + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + }); + } } );