diff --git a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts index 6fb3f6a57eb..389a5d06cbe 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_SAMPLE_NAME || 'Python', + /** * name of workspace created for 'Happy Path' scenario validation. */ diff --git a/tests/e2e/pageobjects/dashboard/Dashboard.ts b/tests/e2e/pageobjects/dashboard/Dashboard.ts index 0eae57ed112..78168ae0930 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_BUTTON: 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_BUTTON, 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 00000000000..ca6b80ccb29 --- /dev/null +++ b/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts @@ -0,0 +1,79 @@ +/** ******************************************************************* + * 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(`"Existing workspace found" 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(`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 workspaceHandlingTests.stopWorkspace(existedWorkspaceName); + 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 cd96c54fb20..52c2ff4c054 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('fetching user kubernetes namespace, storing auth token by getting workspaces API URL.'); + 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;