Skip to content

Commit 76c4909

Browse files
authored
[Test] Update "Create a workspace with the same name of an existing workspace from Git URL" test script (#23633)
1 parent 1ab00a5 commit 76c4909

File tree

5 files changed

+183
-4
lines changed

5 files changed

+183
-4
lines changed

tests/e2e/pageobjects/dashboard/CreateWorkspace.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ export class CreateWorkspace {
9494
await this.performTrustAuthorPopup();
9595
}
9696

97+
async setGitRepositoryUrl(factoryUrl: string, timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
98+
Logger.debug(`factoryUrl: "${factoryUrl}"`);
99+
await this.driverHelper.waitVisibility(CreateWorkspace.FACTORY_URL, timeout);
100+
await this.driverHelper.type(CreateWorkspace.FACTORY_URL, Key.chord(factoryUrl), timeout);
101+
}
102+
103+
async getGitRepositoryUrl(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<string> {
104+
Logger.debug();
105+
return await this.driverHelper.waitAndGetValue(CreateWorkspace.FACTORY_URL, timeout);
106+
}
107+
108+
async clickOnCreateAndOpenButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
109+
Logger.debug();
110+
await this.driverHelper.waitAndClick(CreateWorkspace.CREATE_AND_OPEN_BUTTON, timeout);
111+
}
112+
97113
async clickOnEditorsDropdownListButton(sampleName: string, timeout: number): Promise<void> {
98114
Logger.debug(`sampleName: "${sampleName}, editor ${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}"`);
99115

tests/e2e/pageobjects/dashboard/Dashboard.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { inject, injectable } from 'inversify';
1111
import 'reflect-metadata';
1212
import { CLASSES } from '../../configs/inversify.types';
13-
import { Alert, By } from 'selenium-webdriver';
13+
import { Alert, By, WebElement } from 'selenium-webdriver';
1414
import { DriverHelper } from '../../utils/DriverHelper';
1515
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
1616
import { Workspaces } from './Workspaces';
@@ -28,7 +28,11 @@ export class Dashboard {
2828
private static readonly USER_SETTINGS_DROPDOWN: By = By.xpath('//header//button/span[text()!=""]//parent::button');
2929
private static readonly INFO_DROPDOWN_BUTTON: By = By.xpath('//button[@aria-label="About Menu"]');
3030
private static readonly ABOUT_DIALOG_WINDOW_CLOSE_BUTTON: By = By.xpath('//button[@aria-label="Close Dialog"]');
31-
private static readonly EXISTING_WORKSPACE_FOUND_ALERT: By = By.xpath('//h4[text()="Existing workspace found"]');
31+
private static readonly EXISTING_WORKSPACE_FOUND_ALERT: By = By.xpath(
32+
'//div[text()="Several workspaces created from the same repository have been found. Should you want to open one of the existing workspaces or create a new one, please choose the corresponding action."]'
33+
);
34+
private static readonly EXISTING_WORKSPACE_FOUND_LIST: By = By.xpath('//button//span[text()="Open the existing workspace"]');
35+
private static readonly EXISTING_WORKSPACE_NAME: By = By.xpath('//li//a[text()="python-hello-world"]"]');
3236
private static readonly CREATE_NEW_WORKSPACE_LINK: By = By.xpath('//button[text()="Create a new workspace"]');
3337
private static readonly ABOUT_DIALOG_ITEM_DATA_TEST_IDS: any = {
3438
serverVersion: 'server-version',
@@ -180,6 +184,15 @@ export class Dashboard {
180184
await this.driverHelper.waitVisibility(Dashboard.EXISTING_WORKSPACE_FOUND_ALERT, timeout);
181185
}
182186

187+
async startExistedWorkspace(workspaceName: string): Promise<void> {
188+
Logger.debug();
189+
190+
await this.driverHelper.waitVisibility(Dashboard.EXISTING_WORKSPACE_FOUND_LIST);
191+
const element: WebElement = await this.driverHelper.waitPresence(Dashboard.EXISTING_WORKSPACE_FOUND_LIST);
192+
await this.driverHelper.getDriver().executeScript('arguments[0].click();', element);
193+
await this.driverHelper.waitAndClick(By.xpath(`//li//a[text()="${workspaceName}"]`));
194+
}
195+
183196
async clickOnCreateNewWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
184197
Logger.debug();
185198

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/** *******************************************************************
2+
* copyright (c) 2020-2025 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
import { e2eContainer } from '../../configs/inversify.config';
11+
import { ViewSection } from 'monaco-page-objects';
12+
import { CLASSES } from '../../configs/inversify.types';
13+
import { expect } from 'chai';
14+
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
15+
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
16+
import { LoginTests } from '../../tests-library/LoginTests';
17+
import { registerRunningWorkspace } from '../MochaHooks';
18+
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
19+
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
20+
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
21+
import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS';
22+
import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace';
23+
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
24+
25+
const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || 'python-hello-world';
26+
27+
suite(`"Start workspace with existed workspace name" test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
28+
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
29+
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
30+
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
31+
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
32+
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
33+
const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace);
34+
35+
let projectSection: ViewSection;
36+
let firstWorkspaceName: string;
37+
let secondWorkspaceName: string;
38+
const factoryUrl: string = BASE_TEST_CONSTANTS.IS_CLUSTER_DISCONNECTED()
39+
? FACTORY_TEST_CONSTANTS.TS_SELENIUM_AIRGAP_FACTORY_GIT_REPO_URL || 'https://gh.crw-qe.com/test-automation-only/python-hello-world'
40+
: FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || 'https://github.com/crw-qe/python-hello-world';
41+
42+
suiteSetup('Login', async function (): Promise<void> {
43+
await loginTests.loginIntoChe();
44+
});
45+
46+
async function waitDashboardPage(): Promise<void> {
47+
await dashboard.openDashboard();
48+
await dashboard.waitPage();
49+
await browserTabsUtil.closeAllTabsExceptCurrent();
50+
51+
await dashboard.clickCreateWorkspaceButton();
52+
await createWorkspace.waitPage();
53+
expect(await createWorkspace.isCreateNewWorkspaceCheckboxChecked()).to.be.true;
54+
}
55+
56+
async function waitWorkspaceReadiness(): Promise<void> {
57+
const originalWindowHandle: string = await browserTabsUtil.getCurrentWindowHandle();
58+
await browserTabsUtil.waitAndSwitchToAnotherWindow(originalWindowHandle, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
59+
60+
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
61+
62+
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
63+
64+
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
65+
projectSection = await projectAndFileTests.getProjectViewSession();
66+
expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not.undefined;
67+
expect(
68+
await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME),
69+
'Project files were not imported'
70+
).not.undefined;
71+
}
72+
73+
test('Verify "Create New" is off and a new workspace is created', async function (): Promise<void> {
74+
await waitDashboardPage();
75+
76+
await createWorkspace.setGitRepositoryUrl(factoryUrl);
77+
expect(await createWorkspace.isCreateNewWorkspaceCheckboxChecked()).to.be.false;
78+
expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl);
79+
await createWorkspace.clickOnCreateAndOpenButton();
80+
await createWorkspace.performTrustAuthorPopup();
81+
82+
await waitWorkspaceReadiness();
83+
84+
firstWorkspaceName = WorkspaceHandlingTests.getWorkspaceName();
85+
});
86+
87+
test('Verify existing workspace opens instead of creating a duplicate', async function (): Promise<void> {
88+
await waitDashboardPage();
89+
90+
await createWorkspace.setGitRepositoryUrl(factoryUrl);
91+
expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl);
92+
await createWorkspace.clickOnCreateAndOpenButton();
93+
await createWorkspace.performTrustAuthorPopup();
94+
95+
await waitWorkspaceReadiness();
96+
97+
expect(WorkspaceHandlingTests.getWorkspaceName()).to.be.equal(firstWorkspaceName);
98+
});
99+
100+
test('Ensure `new` is appended and a new workspace is created without warnings', async function (): Promise<void> {
101+
await waitDashboardPage();
102+
103+
await createWorkspace.setGitRepositoryUrl(factoryUrl);
104+
await createWorkspace.setCreateNewWorkspaceCheckbox(true);
105+
106+
expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl + '?new');
107+
108+
await createWorkspace.clickOnCreateAndOpenButton();
109+
await createWorkspace.performTrustAuthorPopup();
110+
111+
await waitWorkspaceReadiness();
112+
113+
secondWorkspaceName = WorkspaceHandlingTests.getWorkspaceName();
114+
// validate workspace name follows pattern: firstWorkspaceName + "-xxxx" (4 alphanumeric chars)
115+
expect(secondWorkspaceName).to.match(new RegExp(`^${firstWorkspaceName}-[a-z0-9]{4}$`));
116+
});
117+
118+
test('Verify warning appears with list of existing workspaces and open the first created workspace', async function (): Promise<void> {
119+
await waitDashboardPage();
120+
121+
await createWorkspace.setGitRepositoryUrl(factoryUrl);
122+
await createWorkspace.clickOnCreateAndOpenButton();
123+
await createWorkspace.performTrustAuthorPopup();
124+
const originalWindowHandle: string = await browserTabsUtil.getCurrentWindowHandle();
125+
await browserTabsUtil.waitAndSwitchToAnotherWindow(originalWindowHandle, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
126+
127+
await dashboard.waitExistingWorkspaceFoundAlert();
128+
await dashboard.startExistedWorkspace(firstWorkspaceName);
129+
130+
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
131+
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
132+
133+
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
134+
projectSection = await projectAndFileTests.getProjectViewSession();
135+
expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not.undefined;
136+
expect(
137+
await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME),
138+
'Project files were not imported'
139+
).not.undefined;
140+
});
141+
142+
suiteTeardown('Stop and delete all created workspaces', async function (): Promise<void> {
143+
await workspaceHandlingTests.stopAndRemoveWorkspace(firstWorkspaceName);
144+
await workspaceHandlingTests.stopAndRemoveWorkspace(secondWorkspaceName);
145+
});
146+
147+
suiteTeardown('Unregister running workspace', function (): void {
148+
registerRunningWorkspace('');
149+
});
150+
});

tests/e2e/suites/disconnected-ocp/UITest.suite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import '../../specs/dashboard-samples/Quarkus.spec';
1111
import '../../specs/dashboard-samples/RecommendedExtensions.spec';
1212
import '../../specs/dashboard-samples/Documentation.spec';
1313
import '../../specs/devconsole-intergration/DevConsoleIntegration.spec';
14-
import '../../specs/miscellaneous/CreateWorkspaceWithExistedName.spec';
14+
import '../../specs/miscellaneous/CreateWorkspaceWithExistingNameFromGitUrl.spec';
1515
import '../../specs/miscellaneous/WorkspaceWithParent.spec';
1616
import '../../specs/miscellaneous/PredefinedNamespace.spec';

tests/e2e/suites/online-ocp/UITest.suite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import '../../specs/dashboard-samples/Quarkus.spec';
1313
import '../../specs/dashboard-samples/RecommendedExtensions.spec';
1414
import '../../specs/dashboard-samples/Documentation.spec';
1515
import '../../specs/devconsole-intergration/DevConsoleIntegration.spec';
16-
import '../../specs/miscellaneous/CreateWorkspaceWithExistedName.spec';
16+
import '../../specs/miscellaneous/CreateWorkspaceWithExistingNameFromGitUrl.spec';
1717
import '../../specs/miscellaneous/KubedockPodmanTest.spec';
1818
import '../../specs/miscellaneous/WorkspaceWithParent.spec';
1919
import '../../specs/miscellaneous/PredefinedNamespace.spec';

0 commit comments

Comments
 (0)