-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathWorkspaceHandlingTests.ts
132 lines (117 loc) · 6.91 KB
/
WorkspaceHandlingTests.ts
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
/*********************************************************************
* Copyright (c) 2019 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 'reflect-metadata';
import { inject, injectable } from 'inversify';
import { CLASSES } from '../inversify.types';
import { Dashboard } from '../pageobjects/dashboard/Dashboard';
import { CreateWorkspace } from '../pageobjects/dashboard/CreateWorkspace';
import { Workspaces } from '../pageobjects/dashboard/Workspaces';
import { BrowserTabsUtil } from '../utils/BrowserTabsUtil';
import { Logger } from '../utils/Logger';
import { ApiUrlResolver } from '../utils/workspace/ApiUrlResolver';
import { TimeoutConstants } from '../TimeoutConstants';
import { DriverHelper } from '../utils/DriverHelper';
import { By, error } from 'selenium-webdriver';
import { TestConstants } from '../TestConstants';
@injectable()
export class WorkspaceHandlingTests {
public static getWorkspaceName(): string {
return WorkspaceHandlingTests.workspaceName;
}
public static setWorkspaceName(workspaceName: string): void {
WorkspaceHandlingTests.workspaceName = workspaceName;
}
private static WORKSPACE_NAME_LOCATOR: By = By.xpath(`//h1[contains(.,'Starting workspace ')]`);
private static workspaceName: string = 'undefined';
private static parentGUID: string;
constructor(
@inject(CLASSES.Dashboard) private readonly dashboard: Dashboard,
@inject(CLASSES.CreateWorkspace) private readonly createWorkspace: CreateWorkspace,
@inject(CLASSES.Workspaces) private readonly workspaces: Workspaces,
@inject(CLASSES.BrowserTabsUtil) private readonly browserTabsUtil: BrowserTabsUtil,
@inject(CLASSES.ApiUrlResolver) private readonly apiUrlResolver: ApiUrlResolver,
@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) {}
public setWindowHandle(guid: string): void {
WorkspaceHandlingTests.parentGUID = guid;
}
public getWindowHandle(): string {
return WorkspaceHandlingTests.parentGUID;
}
public createAndOpenWorkspace(stack: string): void {
test(`Create and open new workspace, stack:${stack}`, async () => {
await this.dashboard.waitPage();
Logger.debug(`Fetching user kubernetes namespace, storing auth token by getting workspaces API URL.`);
await this.apiUrlResolver.getWorkspacesApiUrl();
await this.dashboard.clickCreateWorkspaceButton();
await this.createWorkspace.waitPage();
WorkspaceHandlingTests.parentGUID = await this.browserTabsUtil.getCurrentWindowHandle();
await this.createWorkspace.clickOnSampleForSpecificEditor(stack);
await this.browserTabsUtil.waitAndSwitchToAnotherWindow(WorkspaceHandlingTests.parentGUID, TimeoutConstants.TS_IDE_LOAD_TIMEOUT);
});
}
public openExistingWorkspace(workspaceName: string): void {
test('Open and start existing workspace', async () => {
await this.dashboard.waitPage();
Logger.debug(`Fetching user kubernetes namespace, storing auth token by getting workspaces API URL.`);
await this.apiUrlResolver.getWorkspacesApiUrl();
await this.dashboard.clickWorkspacesButton();
await this.workspaces.waitPage();
await this.workspaces.clickOpenButton(workspaceName);
});
}
public obtainWorkspaceNameFromStartingPage(): void {
test('Obtain workspace name from workspace loader page', async() => {
const timeout: number = TimeoutConstants.TS_IDE_LOAD_TIMEOUT;
const polling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING;
const attempts: number = Math.ceil(timeout / polling);
for (let i: number = 0; i < attempts; i++) {
try {
let startingWorkspaceLineContent: string = await this.driverHelper.getDriver().findElement(WorkspaceHandlingTests.WORKSPACE_NAME_LOCATOR).getText();
Logger.trace(`WorkspaceHandlingTests.obtainWorkspaceNameFromStartingPage obtained starting workspace getText():${startingWorkspaceLineContent}`);
// cutting away leading text
WorkspaceHandlingTests.workspaceName = startingWorkspaceLineContent.substring('Starting workspace '.length).trim();
Logger.trace(`WorkspaceHandlingTests.obtainWorkspaceNameFromStartingPage trimmed workspace name from getText():${WorkspaceHandlingTests.workspaceName}`);
break;
} catch (err) {
if (err instanceof error.StaleElementReferenceError) {
Logger.warn(`WorkspaceHandlingTests.obtainWorkspaceNameFromStartingPage Failed to obtain name from workspace start page, element possibly detached from DOM. Retrying.`);
await this.driverHelper.wait(polling);
continue;
}
if (err instanceof error.NoSuchElementError) {
Logger.warn(`WorkspaceHandlingTests.obtainWorkspaceNameFromStartingPage Failed to obtain name from workspace start page, element not visible yet. Retrying.`);
await this.driverHelper.wait(polling);
continue;
}
Logger.error(`WorkspaceHandlingTests.obtainWorkspaceNameFromStartingPage Obtaining workspace name failed with an unexpected error:${err}`);
throw err;
}
}
if (WorkspaceHandlingTests.workspaceName !== '' && WorkspaceHandlingTests.workspaceName !== undefined) {
Logger.info(`Obtained workspace name from workspace loader page: ${WorkspaceHandlingTests.workspaceName}`);
return;
}
Logger.error(`WorkspaceHandlingTests.obtainWorkspaceNameFromSartingPage failed to obtain workspace name:${WorkspaceHandlingTests.workspaceName}`);
throw new error.InvalidArgumentError(`WorkspaceHandlingTests.obtainWorkspaceNameFromSartingPage failed to obtain workspace name:${WorkspaceHandlingTests.workspaceName}`);
});
}
public async stopWorkspace(workspaceName: string): Promise<void> {
await this.dashboard.openDashboard();
await this.dashboard.stopWorkspaceByUI(workspaceName);
}
public async removeWorkspace(workspaceName: string): Promise<void> {
await this.dashboard.openDashboard();
await this.dashboard.deleteStoppedWorkspaceByUI(workspaceName);
}
public async stopAndRemoveWorkspace(workspaceName: string): Promise<void> {
await this.dashboard.openDashboard();
await this.dashboard.stopAndRemoveWorkspaceByUI(workspaceName);
}
}