Skip to content

Commit 73eeef8

Browse files
authored
[Test] Add methods to work with the new "Create New" workspace feature in CreateWorkspace page object.
1 parent 753c9f1 commit 73eeef8

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

tests/e2e/pageobjects/dashboard/CreateWorkspace.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { inject, injectable } from 'inversify';
1212
import { CLASSES } from '../../configs/inversify.types';
1313
import { DriverHelper } from '../../utils/DriverHelper';
14-
import { By, Key } from 'selenium-webdriver';
14+
import { By, Key, WebElement } from 'selenium-webdriver';
1515
import { Logger } from '../../utils/Logger';
1616
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
1717
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
@@ -24,6 +24,8 @@ export class CreateWorkspace {
2424
private static readonly GIT_BRANCH_NAME: By = By.xpath('//input[@aria-label="Git Branch"]');
2525
private static readonly PATH_TO_DEVFILE: By = By.xpath('//input[@aria-label="Path to Devfile"]');
2626
private static readonly CREATE_AND_OPEN_BUTTON: By = By.xpath('//button[@id="create-and-open-button"]');
27+
private static readonly CREATE_NEW_WORKPACE_CHECKBOX: By = By.xpath('//label[@for="create-new-if-exist-switch"]');
28+
private static readonly CREATE_NEW_WORKPACE_CHECKBOX_VALUE: By = By.xpath('//input[@id="create-new-if-exist-switch"]');
2729

2830
constructor(
2931
@inject(CLASSES.DriverHelper)
@@ -109,6 +111,40 @@ export class CreateWorkspace {
109111
}
110112
}
111113

114+
async isCreateNewWorkspaceCheckboxChecked(timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL): Promise<boolean> {
115+
Logger.debug();
116+
117+
const element: WebElement = await this.driverHelper.waitPresence(CreateWorkspace.CREATE_NEW_WORKPACE_CHECKBOX_VALUE, timeout);
118+
return await element.isSelected();
119+
}
120+
121+
async clickOnCreateNewWorkspaceCheckbox(timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL): Promise<void> {
122+
Logger.debug();
123+
124+
await this.driverHelper.waitAndClick(CreateWorkspace.CREATE_NEW_WORKPACE_CHECKBOX, timeout);
125+
}
126+
127+
async setCreateNewWorkspaceCheckbox(
128+
checked: boolean = true,
129+
timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_WAIT_FOR_URL
130+
): Promise<void> {
131+
Logger.debug(`checked: ${checked}`);
132+
133+
// check current state
134+
const isCurrentlyChecked: boolean = await this.isCreateNewWorkspaceCheckboxChecked(timeout);
135+
136+
// if already in desired state, do nothing
137+
if (isCurrentlyChecked === checked) {
138+
Logger.debug(`Checkbox is already ${checked ? 'set' : 'unset'}, no action needed`);
139+
return;
140+
}
141+
142+
// click to change state
143+
Logger.debug(`Checkbox is ${isCurrentlyChecked ? 'set' : 'unset'}, ${checked ? 'setting' : 'unsetting'} it now`);
144+
await this.driverHelper.waitAndClick(CreateWorkspace.CREATE_NEW_WORKPACE_CHECKBOX, timeout);
145+
await this.driverHelper.wait(1000);
146+
}
147+
112148
private getEditorsDropdownListLocator(sampleName: string): By {
113149
return By.xpath(`//div[text()=\'${sampleName}\']//parent::article//button`);
114150
}

tests/e2e/tests-library/WorkspaceHandlingTests.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,30 @@ export class WorkspaceHandlingTests {
4949
WorkspaceHandlingTests.workspaceName = 'undefined';
5050
}
5151

52-
async createAndOpenWorkspace(stack: string): Promise<void> {
52+
async createAndOpenWorkspace(stack: string, createNewWorkspace: boolean = true): Promise<void> {
5353
await this.dashboard.clickWorkspacesButton();
5454
await this.dashboard.waitPage();
5555
Logger.debug('fetching user kubernetes namespace, storing auth token by getting workspaces API URL.');
5656
await this.apiUrlResolver.getWorkspacesApiUrl();
5757
await this.dashboard.clickCreateWorkspaceButton();
5858
await this.createWorkspace.waitPage();
59+
await this.createWorkspace.setCreateNewWorkspaceCheckbox(createNewWorkspace);
5960
WorkspaceHandlingTests.parentGUID = await this.browserTabsUtil.getCurrentWindowHandle();
6061
await this.createWorkspace.clickOnSampleNoEditorSelection(stack);
6162
await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);
6263
}
6364

64-
async createAndOpenWorkspaceFromGitRepository(factoryUrl: string, branchName?: string): Promise<void> {
65+
async createAndOpenWorkspaceFromGitRepository(
66+
factoryUrl: string,
67+
branchName?: string,
68+
createNewWorkspace: boolean = true
69+
): Promise<void> {
6570
await this.dashboard.waitPage();
6671
Logger.debug('fetching user kubernetes namespace, storing auth token by getting workspaces API URL.');
6772
await this.apiUrlResolver.getWorkspacesApiUrl();
6873
await this.dashboard.clickCreateWorkspaceButton();
6974
await this.createWorkspace.waitPage();
75+
await this.createWorkspace.setCreateNewWorkspaceCheckbox(createNewWorkspace);
7076
WorkspaceHandlingTests.parentGUID = await this.browserTabsUtil.getCurrentWindowHandle();
7177
await this.createWorkspace.importFromGitUsingUI(factoryUrl, branchName);
7278
await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT);

0 commit comments

Comments
 (0)