Skip to content

Commit

Permalink
[Test] Create automated test for "Existing workspace found" scenario (#…
Browse files Browse the repository at this point in the history
…22503)

* create CreateWorkspaceWithExistedName e2e test
  • Loading branch information
SkorikSergey authored and musienko-maxim committed Sep 12, 2023
1 parent 6ea1ad6 commit e3ae1d6
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
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 @@ -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;
} = {
Expand All @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/constants/TIMEOUT_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------

Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/pageobjects/dashboard/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<void> {
Logger.debug();

await this.driverHelper.waitVisibility(Dashboard.EXISTING_WORKSPACE_FOUND_ALERT, timeout);
}

async clickOnCreateNewWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
Logger.debug();

await this.driverHelper.waitAndClick(Dashboard.CREATE_NEW_WORKSPACE_LINK, timeout);
}

async logout(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
await workspaceHandlingTests.createAndOpenWorkspace(stackName);
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});

test('Wait workspace readiness and project folder has been created', async function (): Promise<void> {
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<void> {
existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName();
await workspaceHandlingTests.stopWorkspace(existedWorkspaceName);
await browserTabsUtil.closeAllTabsExceptCurrent();
});

test(`Create new workspace from the same ${stackName} stack`, async function (): Promise<void> {
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<void> {
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<void> {
await workspaceHandlingTests.stopWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await browserTabsUtil.closeAllTabsExceptCurrent();
});

test(`Delete all created ${stackName} workspaces`, async function (): Promise<void> {
await workspaceHandlingTests.removeWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await workspaceHandlingTests.removeWorkspace(existedWorkspaceName);
});

loginTests.logoutFromChe();
});
7 changes: 7 additions & 0 deletions tests/e2e/tests-library/WorkspaceHandlingTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export class WorkspaceHandlingTests {
await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
}

async createAndOpenWorkspaceWithExistedWorkspaceName(stack: string): Promise<void> {
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<void> {
const timeout: number = TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT;
const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING;
Expand Down

0 comments on commit e3ae1d6

Please sign in to comment.