From e3ae1d6834c5d40e51c89406387c3118c31388c4 Mon Sep 17 00:00:00 2001 From: Sergey Skorik Date: Tue, 12 Sep 2023 13:08:06 +0300 Subject: [PATCH] [Test] Create automated test for "Existing workspace found" scenario (#22503) * create CreateWorkspaceWithExistedName e2e test --- tests/e2e/constants/BASE_TEST_CONSTANTS.ts | 6 ++ tests/e2e/constants/TIMEOUT_CONSTANTS.ts | 2 +- tests/e2e/pageobjects/dashboard/Dashboard.ts | 14 ++++ .../CreateWorkspaceWithExistedName.spec.ts | 84 +++++++++++++++++++ .../tests-library/WorkspaceHandlingTests.ts | 7 ++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts diff --git a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts index 6fb3f6a57ebe..ec3161681234 100644 --- a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts @@ -22,6 +22,7 @@ export const BASE_TEST_CONSTANTS: { TS_LOAD_TESTS: string; TS_SELENIUM_REQUEST_INTERCEPTOR: boolean; TS_SELENIUM_PROJECT_ROOT_FILE_NAME: string; + TS_SELENIUM_DASHBOARD_SAMPLE_NAME: string; TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME: string; IS_CLUSTER_DISCONNECTED: () => boolean; } = { @@ -48,6 +49,11 @@ export const BASE_TEST_CONSTANTS: { */ TS_SELENIUM_PROJECT_ROOT_FILE_NAME: process.env.TS_SELENIUM_PROJECT_ROOT_FILE_NAME || 'devfile.yaml', + /** + * sample name from Dashboard to start + */ + TS_SELENIUM_DASHBOARD_SAMPLE_NAME: process.env.TS_SELENIUM_DASHBOARD_SAMPLE_NAME || 'Python', + /** * name of workspace created for 'Happy Path' scenario validation. */ diff --git a/tests/e2e/constants/TIMEOUT_CONSTANTS.ts b/tests/e2e/constants/TIMEOUT_CONSTANTS.ts index c72e39d8c0c0..6a3649e7402e 100644 --- a/tests/e2e/constants/TIMEOUT_CONSTANTS.ts +++ b/tests/e2e/constants/TIMEOUT_CONSTANTS.ts @@ -94,7 +94,7 @@ export const TIMEOUT_CONSTANTS: { /** * timeout for workspace stopped status, "30 000" by default */ - TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT: Number(process.env.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT) || 30_000, + TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT: Number(process.env.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT) || 60_000, // -------------------------------------------- PROJECT TREE -------------------------------------------- diff --git a/tests/e2e/pageobjects/dashboard/Dashboard.ts b/tests/e2e/pageobjects/dashboard/Dashboard.ts index 0eae57ed112b..ada62e72971a 100644 --- a/tests/e2e/pageobjects/dashboard/Dashboard.ts +++ b/tests/e2e/pageobjects/dashboard/Dashboard.ts @@ -26,6 +26,8 @@ export class Dashboard { private static readonly LOADER_ALERT: By = By.xpath('//*[@data-testid="loader-alert"]'); private static readonly LOGOUT_BUTTON: By = By.xpath('//button[text()="Logout"]'); private static readonly USER_SETTINGS_DROPDOWN: By = By.xpath('//header//button/span[text()!=""]//parent::button'); + private static readonly EXISTING_WORKSPACE_FOUND_ALERT: By = By.xpath('//h4[text()="Existing workspace found"]'); + private static readonly CREATE_NEW_WORKSPACE_LINK: By = By.xpath('//button[text()="Create a new workspace"]'); constructor( @inject(CLASSES.DriverHelper) @@ -107,6 +109,18 @@ export class Dashboard { await this.driverHelper.wait(TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING); } + async waitExistingWorkspaceFoundAlert(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise { + Logger.debug(); + + await this.driverHelper.waitVisibility(Dashboard.EXISTING_WORKSPACE_FOUND_ALERT, timeout); + } + + async clickOnCreateNewWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise { + Logger.debug(); + + await this.driverHelper.waitAndClick(Dashboard.CREATE_NEW_WORKSPACE_LINK, timeout); + } + async logout(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise { Logger.debug(); diff --git a/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts b/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts new file mode 100644 index 000000000000..c9111b9a5936 --- /dev/null +++ b/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts @@ -0,0 +1,84 @@ +/** ******************************************************************* + * 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 { ViewSection, SideBarView, ViewItem } from 'monaco-page-objects'; +import { CLASSES } from '../../configs/inversify.types'; +import { expect } from 'chai'; +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; +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 { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; + +const stackName: string = BASE_TEST_CONSTANTS.TS_SELENIUM_DASHBOARD_SAMPLE_NAME || 'Python'; +const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || 'python-hello-world'; + +suite(`"Start workspace with existed workspace name" 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 browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); + const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); + let projectSection: ViewSection; + let existedWorkspaceName: string; + + loginTests.loginIntoChe(); + + test(`Create and open new workspace, stack:${stackName}`, async function (): Promise { + await workspaceHandlingTests.createAndOpenWorkspace(stackName); + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + }); + + test('Wait workspace readiness and project folder has been created', async function (): Promise { + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); + projectSection = await new SideBarView().getContent().getSection(projectName); + const isFileImported: ViewItem | undefined = await projectSection.findItem(BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME); + expect(isFileImported).not.eqls(undefined); + }); + + test(`Stop created workspace`, async function (): Promise { + existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); + await workspaceHandlingTests.stopWorkspace(existedWorkspaceName); + await browserTabsUtil.closeAllTabsExceptCurrent(); + }); + + test(`Create new workspace from the same ${stackName} stack`, async function (): Promise { + existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); + + await browserTabsUtil.navigateTo(BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL); + await dashboard.waitPage(); + await workspaceHandlingTests.createAndOpenWorkspaceWithExistedWorkspaceName(stackName); + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + }); + + test('Wait the second workspace readiness and project folder has been created', async function (): Promise { + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); + projectSection = await new SideBarView().getContent().getSection(projectName); + const isFileImported: ViewItem | undefined = await projectSection.findItem(BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME); + expect(isFileImported).not.eqls(undefined); + }); + + test(`Stop all created ${stackName} workspaces`, async function (): Promise { + await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + await browserTabsUtil.closeAllTabsExceptCurrent(); + }); + + test(`Delete all created ${stackName} workspaces`, async function (): Promise { + await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName()); + await workspaceHandlingTests.removeWorkspace(existedWorkspaceName); + }); + + loginTests.logoutFromChe(); +}); diff --git a/tests/e2e/tests-library/WorkspaceHandlingTests.ts b/tests/e2e/tests-library/WorkspaceHandlingTests.ts index cd96c54fb203..c3bf362febea 100644 --- a/tests/e2e/tests-library/WorkspaceHandlingTests.ts +++ b/tests/e2e/tests-library/WorkspaceHandlingTests.ts @@ -73,6 +73,13 @@ export class WorkspaceHandlingTests { await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); } + async createAndOpenWorkspaceWithExistedWorkspaceName(stack: string): Promise { + Logger.debug('create and open workspace with existed workspace name.'); + await this.createAndOpenWorkspace(stack); + await this.dashboard.waitExistingWorkspaceFoundAlert(); + await this.dashboard.clickOnCreateNewWorkspaceButton(); + } + async obtainWorkspaceNameFromStartingPage(): Promise { const timeout: number = TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT; const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING;