From 82a17bac65021f49aee6cc3df2f7905119373dba Mon Sep 17 00:00:00 2001 From: Skoryk Serhii Date: Fri, 29 Sep 2023 12:12:42 +0300 Subject: [PATCH 1/4] create WorkspaceIdleTimeout test --- .../pageobjects/ide/CheCodeLocatorLoader.ts | 3 + .../WorkspaceIdleTimeout.spec.ts | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts diff --git a/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts b/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts index 51a7203e3b9..63d76135b41 100644 --- a/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts +++ b/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts @@ -40,6 +40,9 @@ export class CheCodeLocatorLoader extends LocatorLoader { WelcomeContent: { text: By.xpath('//*[@class="dialog-message-text" and contains(text(), "trust")]'), button: By.xpath('//div[@class="monaco-dialog-box"]//a[@class="monaco-button monaco-text-button"]') + }, + Dialog: { + message: By.xpath('//*[@class="dialog-message-detail"]'), } }, extras: { diff --git a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts new file mode 100644 index 00000000000..073fcc8718b --- /dev/null +++ b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts @@ -0,0 +1,66 @@ +/** ******************************************************************* + * copyright (c) 2020-2023 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +import { e2eContainer } from '../../configs/inversify.config'; +import { CLASSES } from '../../configs/inversify.types'; +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; +import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; +import { LoginTests } from '../../tests-library/LoginTests'; +import { registerRunningWorkspace } from '../MochaHooks'; +import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import { Workspaces } from '../../pageobjects/dashboard/Workspaces'; +import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; +import { DriverHelper } from '../../utils/DriverHelper'; +import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader'; +import { Locators, ModalDialog } from 'monaco-page-objects'; +import { expect } from 'chai'; + +const stackName: string = 'Empty Workspace'; + +suite('"Check workspace idle timeout" test', function (): void { + const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); + const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); + const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); + const workspaces: Workspaces = e2eContainer.get(CLASSES.Workspaces); + const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); + const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader); + const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators; + + loginTests.loginIntoChe(); + + test(`Create and open new workspace, stack:${stackName}`, async function (): Promise { + await workspaceHandlingTests.createAndOpenWorkspace(stackName); + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + }); + + test('Wait workspace readiness', async function (): Promise { + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); + await projectAndFileTests.performTrustAuthorDialog(); + }); + + test('Wait idle timeout dialog and click on "Return to Dashboard" button', async function (): Promise { + await driverHelper.waitVisibility(webCheCodeLocators.Dialog.details, TIMEOUT_CONSTANTS.TS_SELENIUM_START_WORKSPACE_TIMEOUT); + const dialog: ModalDialog = new ModalDialog(); + expect(await dialog.getMessage()).includes('Your workspace has stopped due to inactivity.'); + await dialog.pushButton('Return to dashboard'); + }); + + test('Check that the workskpace has Stopped state', async function (): Promise { + await dashboard.waitPage(); + await workspaces.waitWorkspaceWithStoppedStatus(WorkspaceHandlingTests.getWorkspaceName()); + }); + + test('Delete the workspace', async function (): Promise { + await dashboard.deleteStoppedWorkspaceByUI(WorkspaceHandlingTests.getWorkspaceName()); + }); + + loginTests.logoutFromChe(); +}); From 2486feab18785b858e94b8b0579cc892515325c2 Mon Sep 17 00:00:00 2001 From: Skoryk Serhii Date: Mon, 9 Oct 2023 14:35:22 +0300 Subject: [PATCH 2/4] revert Dialog message locator changes --- tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts | 3 --- tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts b/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts index 63d76135b41..51a7203e3b9 100644 --- a/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts +++ b/tests/e2e/pageobjects/ide/CheCodeLocatorLoader.ts @@ -40,9 +40,6 @@ export class CheCodeLocatorLoader extends LocatorLoader { WelcomeContent: { text: By.xpath('//*[@class="dialog-message-text" and contains(text(), "trust")]'), button: By.xpath('//div[@class="monaco-dialog-box"]//a[@class="monaco-button monaco-text-button"]') - }, - Dialog: { - message: By.xpath('//*[@class="dialog-message-detail"]'), } }, extras: { diff --git a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts index 073fcc8718b..0981edde4e4 100644 --- a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts +++ b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts @@ -49,7 +49,7 @@ suite('"Check workspace idle timeout" test', function (): void { test('Wait idle timeout dialog and click on "Return to Dashboard" button', async function (): Promise { await driverHelper.waitVisibility(webCheCodeLocators.Dialog.details, TIMEOUT_CONSTANTS.TS_SELENIUM_START_WORKSPACE_TIMEOUT); const dialog: ModalDialog = new ModalDialog(); - expect(await dialog.getMessage()).includes('Your workspace has stopped due to inactivity.'); + expect(await dialog.getDetails()).includes('Your workspace has stopped due to inactivity.'); await dialog.pushButton('Return to dashboard'); }); From cd94bc0a6ac1cc6dc6a75f9eb283fca21dfb0125 Mon Sep 17 00:00:00 2001 From: Skoryk Serhii Date: Mon, 9 Oct 2023 17:15:53 +0300 Subject: [PATCH 3/4] add comments test-case steps --- .../e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts index 0981edde4e4..1b3f94e0939 100644 --- a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts +++ b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts @@ -21,6 +21,14 @@ import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader import { Locators, ModalDialog } from 'monaco-page-objects'; import { expect } from 'chai'; +/** Test scenario for workspace idle timeout test-case: + * 1. Preset spec.devEnvironments.secondsOfInactivityBeforeIdling:180 in CheCluster + * 2. Start workspace using VS Code Editor + * 3. Wait for Dialog with `Your workspace has stopped due to inactivity.` message. + * 4. Click on `Return to Dashboard` button. + * 5. Make sure test workspace status is Stopped in Dashboard. + */ + const stackName: string = 'Empty Workspace'; suite('"Check workspace idle timeout" test', function (): void { From 1ca07445d14cd98d37d554311d655ba8152abcf9 Mon Sep 17 00:00:00 2001 From: Skoryk Serhii Date: Tue, 10 Oct 2023 13:50:45 +0300 Subject: [PATCH 4/4] patch checluster to change secondsOfInactivityBeforeIdling --- .../WorkspaceIdleTimeout.spec.ts | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts index 1b3f94e0939..dd2d0f43932 100644 --- a/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts +++ b/tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts @@ -20,16 +20,8 @@ import { DriverHelper } from '../../utils/DriverHelper'; import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader'; import { Locators, ModalDialog } from 'monaco-page-objects'; import { expect } from 'chai'; - -/** Test scenario for workspace idle timeout test-case: - * 1. Preset spec.devEnvironments.secondsOfInactivityBeforeIdling:180 in CheCluster - * 2. Start workspace using VS Code Editor - * 3. Wait for Dialog with `Your workspace has stopped due to inactivity.` message. - * 4. Click on `Return to Dashboard` button. - * 5. Make sure test workspace status is Stopped in Dashboard. - */ - -const stackName: string = 'Empty Workspace'; +import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor'; +import { ShellExecutor } from '../../utils/ShellExecutor'; suite('"Check workspace idle timeout" test', function (): void { const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); @@ -40,6 +32,38 @@ suite('"Check workspace idle timeout" test', function (): void { const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper); const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader); const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators; + const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( + CLASSES.KubernetesCommandLineToolsExecutor + ); + const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); + + const stackName: string = 'Empty Workspace'; + const cheClusterName: string = 'devspaces'; + let stopWorkspaceTimeout: number = 0; + + suiteSetup(function (): void { + kubernetesCommandLineToolsExecutor.loginToOcp('admin'); + shellExecutor.executeCommand('oc project openshift-devspaces'); + + // get current value of spec.devEnvironments.secondsOfInactivityBeforeIdling + stopWorkspaceTimeout = Number( + shellExecutor.executeCommand( + `oc get checluster/${cheClusterName} -o "jsonpath={.spec.devEnvironments.secondsOfInactivityBeforeIdling}"` + ) + ); + + // set spec.devEnvironments.secondsOfInactivityBeforeIdling to 60 + shellExecutor.executeCommand( + `oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": 60}}}'` + ); + }); + + suiteTeardown(function (): void { + // restore spec.devEnvironments.secondsOfInactivityBeforeIdling to original value + shellExecutor.executeCommand( + `oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": ${stopWorkspaceTimeout}}}}'` + ); + }); loginTests.loginIntoChe();