-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathWorkspaces.ts
More file actions
250 lines (197 loc) · 9.43 KB
/
Workspaces.ts
File metadata and controls
250 lines (197 loc) · 9.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/** *******************************************************************
* copyright (c) 2019-2026 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 { inject, injectable } from 'inversify';
import { DriverHelper } from '../../utils/DriverHelper';
import { CLASSES } from '../../configs/inversify.types';
import { By, WebElement } from 'selenium-webdriver';
import { Logger } from '../../utils/Logger';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
export enum WorkspaceStatusUI {
Running = 'Workspace status is Running',
Stopped = 'Workspace status is Stopped'
}
@injectable()
export class Workspaces {
private static readonly ADD_WORKSPACE_BUTTON: By = By.css('button[aria-label="Add Workspace"]');
private static readonly WORKSPACE_ITEM_TABLE_NAME_SECTION: By = By.xpath('//td[@data-label="Name"]/span/a');
private static readonly DELETE_WORKSPACE_BUTTON_ENABLED: By = By.xpath(
'//button[@data-testid="delete-workspace-button" and not(@disabled)]'
);
private static readonly WORKSPACE_ACTION_POPUP: By = By.css('div[class*="workspaceActionSelector"]');
private static readonly DELETE_CONFIRMATION_CHECKBOX: By = By.xpath('//input[@data-testid="confirmation-checkbox"]');
private static readonly CONFIRMATION_WINDOW: By = By.xpath('//div[@aria-label="Delete workspaces confirmation window"]');
private static readonly LEARN_MORE_DOC_LINK: By = By.xpath('//div/p/a');
constructor(
@inject(CLASSES.DriverHelper)
private readonly driverHelper: DriverHelper
) {}
async waitPage(timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitVisibility(Workspaces.ADD_WORKSPACE_BUTTON, timeout);
}
async clickAddWorkspaceButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(Workspaces.ADD_WORKSPACE_BUTTON, timeout);
}
async clickOpenButton(workspaceName: string, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(this.getOpenButtonLocator(workspaceName), timeout);
}
async waitWorkspaceListItem(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT
): Promise<void> {
Logger.debug(`"${workspaceName}"`);
await this.driverHelper.waitVisibility(this.getWorkspaceListItemLocator(workspaceName), timeout);
}
async waitWorkspaceWithRunningStatus(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT
): Promise<void> {
Logger.debug(`"${workspaceName}"`);
await this.driverHelper.waitVisibility(this.getWorkspaceStatusLocator(workspaceName, WorkspaceStatusUI.Running), timeout);
}
async waitWorkspaceWithStoppedStatus(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT
): Promise<void> {
Logger.debug(`"${workspaceName}"`);
await this.driverHelper.waitVisibility(this.getWorkspaceStatusLocator(workspaceName, WorkspaceStatusUI.Stopped), timeout);
}
async clickWorkspaceListItemLink(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT
): Promise<void> {
Logger.debug(`"${workspaceName}"`);
await this.driverHelper.waitAndClick(this.getOpenWorkspaceDetailsLinkLocator(workspaceName), timeout);
}
async clickActionsButton(workspaceName: string): Promise<void> {
Logger.debug(`of the '${workspaceName}' list item`);
await this.driverHelper.waitAndClick(this.getActionsLocator(workspaceName));
}
async waitActionsPopup(workspaceName: string, timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug(`of the '${workspaceName}' list item`);
await this.driverHelper.waitVisibility(Workspaces.WORKSPACE_ACTION_POPUP, timeout);
}
async openActionsPopup(workspaceName: string, timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug(`for the '${workspaceName}' list item`);
await this.clickActionsButton(workspaceName);
await this.waitActionsPopup(workspaceName, timeout);
}
async clickActionsDeleteButton(workspaceName: string): Promise<void> {
Logger.debug(`for the '${workspaceName}' list item`);
await this.driverHelper.waitAndClick(this.getActionsPopupButtonLocator('Delete Workspace'));
}
async clickActionsStopWorkspaceButton(workspaceName: string): Promise<void> {
Logger.debug(`for the '${workspaceName}' list item`);
// todo: workaround because of issue CRW-3649
try {
await this.driverHelper.waitAndClick(this.getActionsPopupButtonLocator('Stop Workspace'));
} catch (e) {
Logger.warn(`for the '${workspaceName}' list item - popup was missed, try to click one more time (issue CRW-3649).`);
await this.driverHelper.waitAndClick(this.getActionsLocator(workspaceName));
await this.driverHelper.waitAndClick(this.getActionsPopupButtonLocator('Stop Workspace'));
}
}
async waitDeleteWorkspaceConfirmationWindow(timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitVisibility(Workspaces.CONFIRMATION_WINDOW, timeout);
}
async clickToDeleteConfirmationCheckbox(timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(Workspaces.DELETE_CONFIRMATION_CHECKBOX, timeout);
}
async waitAndClickEnabledConfirmationWindowDeleteButton(
timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT
): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(Workspaces.DELETE_WORKSPACE_BUTTON_ENABLED, timeout);
}
async deleteWorkspaceByActionsButton(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT
): Promise<void> {
Logger.debug();
await this.waitWorkspaceListItem(workspaceName, timeout);
await this.openActionsPopup(workspaceName, timeout);
await this.clickActionsDeleteButton(workspaceName);
await this.waitDeleteWorkspaceConfirmationWindow(timeout);
await this.clickToDeleteConfirmationCheckbox(timeout);
await this.waitAndClickEnabledConfirmationWindowDeleteButton(timeout);
}
async stopWorkspaceByActionsButton(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT
): Promise<void> {
Logger.debug();
await this.waitWorkspaceListItem(workspaceName, timeout);
await this.openActionsPopup(workspaceName, timeout);
await this.clickActionsStopWorkspaceButton(workspaceName);
}
async waitWorkspaceListItemAbsence(
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT
): Promise<void> {
Logger.debug(`"${workspaceName}"`);
const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING;
const attempts: number = Math.ceil(timeout / polling);
await this.driverHelper.waitDisappearance(this.getWorkspaceListItemLocator(workspaceName), attempts, polling);
}
async getAllCreatedWorkspacesNames(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<string[]> {
Logger.debug();
const workspaceNames: string[] = [];
try {
const workspaceItems: WebElement[] = await this.driverHelper.waitAllPresence(
Workspaces.WORKSPACE_ITEM_TABLE_NAME_SECTION,
timeout
);
for (const item of workspaceItems) {
Logger.debug(`try to get ${workspaceItems.indexOf(item)} items name`);
workspaceNames.push(await item.getText());
Logger.debug(`workspace name is "${workspaceNames[workspaceNames.length - 1]}"`);
}
} catch (e) {
Logger.debug(`${e}`);
}
Logger.debug(`${workspaceNames.length} workspaces have been created in DevSpaces`);
return workspaceNames;
}
async getLearnMoreDocumentationLink(): Promise<string> {
Logger.debug();
return await this.driverHelper.waitAndGetElementAttribute(Workspaces.LEARN_MORE_DOC_LINK, 'href');
}
private getWorkspaceListItemLocator(workspaceName: string): By {
return By.xpath(`//tr[td//span[text()='${workspaceName}']]`);
}
private getWorkspaceStatusLocator(workspaceName: string, workspaceStatus: WorkspaceStatusUI): By {
return By.xpath(
`${
this.getWorkspaceListItemLocator(workspaceName).value
}//span[@data-testid='workspace-status-indicator' and @aria-label='${workspaceStatus}']`
);
}
private getActionsLocator(workspaceName: string): By {
return By.xpath(`${this.getWorkspaceListItemLocator(workspaceName).value}/td/button[@aria-label='Actions']`);
}
/* private getExpandedActionsLocator(workspaceName: string): By {
return By.xpath(
`${this.getWorkspaceListItemLocator(workspaceName).value}//button[@aria-label='Actions' and @aria-expanded='true']`
);
}*/
private getActionsPopupButtonLocator(buttonText: string): By {
return By.css(`button[aria-label="Action: ${buttonText}"]`);
}
private getOpenButtonLocator(workspaceName: string): By {
return By.xpath(`${this.getWorkspaceListItemLocator(workspaceName).value}//td[contains(@class, 'openIde')]//span[text()='Open']`);
}
private getOpenWorkspaceDetailsLinkLocator(workspaceName: string): By {
return By.xpath(`${this.getWorkspaceListItemLocator(workspaceName).value}//a[text()='${workspaceName}']`);
}
}