Skip to content

Commit 06b87fc

Browse files
Lukas Grossmannvrubezhny
authored andcommitted
Completing add-cluster UI test
Signed-off-by: Lukas Grossmann <lgrossma@redhat.com>
1 parent 4aa33e6 commit 06b87fc

File tree

4 files changed

+189
-24
lines changed

4 files changed

+189
-24
lines changed

test/ui/common/conditions.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
import { BottomBarPanel, InputBox, Notification, NotificationType, ViewItem, ViewSection, WebDriver, Workbench } from 'vscode-extension-tester';
6+
import { BottomBarPanel, EditorView, InputBox, Notification, NotificationType, ViewItem, ViewSection, WebDriver, WelcomeContentSection, Workbench } from 'vscode-extension-tester';
77

88
export async function waitForInputUpdate(input: InputBox, originalText: string, timeout = 5000): Promise<string> {
99
return input.getDriver().wait(async () => {
@@ -80,4 +80,25 @@ export async function terminalHasText(text: string, timeout = 60000, period = 50
8080
}
8181
await new Promise(res => setTimeout(res, period));
8282
}, timeout);
83+
}
84+
85+
export async function welcomeContentButtonsAreLoaded(welcomeContentSection: WelcomeContentSection, timeout = 60_000) {
86+
return welcomeContentSection.getDriver().wait(async () => {
87+
const buttons = await welcomeContentSection.getButtons();
88+
if(buttons.length > 0) {
89+
return buttons
90+
}
91+
}, timeout);
92+
}
93+
94+
export async function webViewIsOpened(name: string, driver: WebDriver, timeout = 10_000) {
95+
return driver.wait(async () => {
96+
try {
97+
const editor = new EditorView();
98+
await editor.openEditor(name)
99+
return true;
100+
} catch(err) {
101+
return null;
102+
}
103+
}, timeout)
83104
}

test/ui/common/ui/webview/addClusterWebView.ts

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,130 @@ export class AddClusterWebView extends WebViewForm {
2929
await this.enterWebView(async (webView) => {
3030
const button = await this.getStartYourOpenshiftExperienceButton(webView);
3131
await button.click();
32-
})
32+
});
33+
}
34+
35+
public async checkLearningButton(): Promise<void> {
36+
await this.enterWebView(async (webView) => {
37+
await this.getStartLearningButton(webView);
38+
});
39+
}
40+
41+
public async checkRosaButton(): Promise<void> {
42+
await this.enterWebView(async (webView) => {
43+
await this.getRosaButton(webView);
44+
});
3345
}
3446

3547
private async getCreateRefreshClusterButton(webView: WebView): Promise<WebElement> {
36-
return await webView.findWebElement(By.xpath('//span[contains(text(),"Create/Refresh cluster")]'));
48+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Create/Refresh cluster")]'));
3749
}
3850

3951
private async getStartYourOpenshiftExperienceButton(webView: WebView): Promise<WebElement> {
40-
return await webView.findElement(By.xpath('//span[contains(text(),"Start your OpenShift experience")]'));
52+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Start your OpenShift experience")]'));
53+
}
54+
55+
private async getStartLearningButton(webView: WebView): Promise<WebElement> {
56+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Start Learning")]'));
57+
}
58+
59+
private async getRosaButton(webView: WebView): Promise<WebElement> {
60+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Create a ROSA cluster")]'));
61+
}
62+
}
63+
64+
export class LocalClusterWebViewPage extends WebViewForm {
65+
66+
public constructor() {
67+
super('Add OpenShift Cluster');
68+
}
69+
70+
public async checkText(): Promise<void> {
71+
await this.enterWebView(async (webView) => {
72+
await this.getText(webView);
73+
});
74+
}
75+
76+
public async checkDownloadButton(): Promise<void> {
77+
await this.enterWebView(async (webView) => {
78+
await this.getDownloadButton(webView);
79+
});
80+
}
81+
82+
public async checkPathButton(): Promise<void> {
83+
await this.enterWebView(async (webView) => {
84+
await this.getPathButton(webView);
85+
});
86+
}
87+
88+
public async clickBack(): Promise<void> {
89+
await this.enterWebView(async (webView) => {
90+
const button = await this.getBackButton(webView);
91+
await button.click();
92+
})
93+
}
94+
95+
private async getText(webView: WebView): Promise<WebElement> {
96+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Red Hat OpenShift Local brings a minimal OpenShift 4 cluster")]'));
97+
}
98+
99+
private async getDownloadButton(webView: WebView): Promise<WebElement> {
100+
return await webView.findWebElement(By.xpath('//*[@role="button" and contains(text(),"Download OpenShift Local")]'));
101+
}
102+
103+
private async getPathButton(webView: WebView): Promise<WebElement> {
104+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Select Path")]'));
105+
}
106+
107+
private async getBackButton(webView: WebView): Promise<WebElement> {
108+
return await webView.findWebElement(By.xpath('//button[contains(text(),"Back")]'));
109+
}
110+
}
111+
112+
export class DevSandboxWebViewPage extends WebViewForm {
113+
114+
public constructor() {
115+
super('Add OpenShift Cluster');
116+
}
117+
118+
public async checkText(): Promise<void> {
119+
await this.enterWebView(async (webView) => {
120+
await this.getText(webView);
121+
});
122+
}
123+
124+
public async checkLoginButton(): Promise<void> {
125+
await this.enterWebView(async (webView) => {
126+
await this.getLoginButton(webView);
127+
});
128+
}
129+
130+
public async checkSignUpButton(): Promise<void> {
131+
await this.enterWebView(async (webView) => {
132+
await this.getSignUpButton(webView);
133+
});
134+
}
135+
136+
public async clickBack(): Promise<void> {
137+
await this.enterWebView(async (webView) => {
138+
const button = await this.getBackButton(webView);
139+
await button.click();
140+
})
141+
}
142+
143+
private async getText(webView: WebView): Promise<WebElement> {
144+
return await webView.findWebElement(By.xpath('//*[contains(text(),"The sandbox provides you with a private OpenShift environment")]'));
145+
}
146+
147+
private async getLoginButton(webView: WebView): Promise<WebElement> {
148+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Login to Red Hat")]'));
149+
}
150+
151+
private async getSignUpButton(webView: WebView): Promise<WebElement> {
152+
return await webView.findWebElement(By.xpath('//*[contains(text(),"Sign Up")]'));
153+
}
154+
155+
private async getBackButton(webView: WebView): Promise<WebElement> {
156+
return await webView.findWebElement(By.xpath('//button[contains(text(),"Back")]'));
41157
}
42158
}

test/ui/public-ui-test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
//import { checkAboutCommand } from './suite/command-about';
7-
//import path = require('path');
8-
//import { testCreateComponent } from './suite/createComponent';
9-
//import { testDevfileRegistries } from './suite/devfileRegistries';
6+
import { checkAboutCommand } from './suite/command-about';
7+
import path = require('path');
8+
import { testCreateComponent } from './suite/createComponent';
9+
import { testDevfileRegistries } from './suite/devfileRegistries';
1010
import { checkExtension } from './suite/extension';
11-
//import { checkFocusOnCommands } from './suite/focusOn';
11+
import { checkFocusOnCommands } from './suite/focusOn';
1212
import { checkOpenshiftView } from './suite/openshift';
13-
//import { testCreateServerlessFunction } from './suite/serverlessFunction';
13+
import { testCreateServerlessFunction } from './suite/serverlessFunction';
1414
import { testAddCluster } from './suite/addCluster';
1515

1616
require('source-map-support').install();
1717

1818
describe('Extension public-facing UI tests', function() {
19-
//const contextFolder = path.join(__dirname, 'context');
19+
const contextFolder = path.join(__dirname, 'context');
2020

2121
checkExtension();
2222
checkOpenshiftView();
2323
testAddCluster();
24-
//checkAboutCommand();
25-
//testDevfileRegistries();
26-
//checkFocusOnCommands();
27-
//testCreateComponent(contextFolder);
28-
//testCreateServerlessFunction(contextFolder);
24+
checkAboutCommand();
25+
testDevfileRegistries();
26+
checkFocusOnCommands();
27+
testCreateComponent(contextFolder);
28+
testCreateServerlessFunction(contextFolder);
2929
});

test/ui/suite/addCluster.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
* Copyright (c) Red Hat, Inc. All rights reserved.
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
5-
import { ActivityBar, EditorView, SideBarView } from 'vscode-extension-tester';
5+
import { ActivityBar, EditorView, SideBarView, VSBrowser } from 'vscode-extension-tester';
66
import { VIEWS } from '../common/constants';
77
import { collapse } from '../common/overdrives';
8-
import { AddClusterWebView } from '../common/ui/webview/addClusterWebView';
8+
import { AddClusterWebView, DevSandboxWebViewPage, LocalClusterWebViewPage } from '../common/ui/webview/addClusterWebView';
9+
import { webViewIsOpened, welcomeContentButtonsAreLoaded } from '../common/conditions';
910

1011
export function testAddCluster() {
1112
describe('Add Cluster', function () {
1213

1314
let view: SideBarView;
15+
let addClusterView;
1416

1517
before(async function context() {
18+
this.timeout(30_000)
19+
//await new Promise((res) => {setTimeout(res, 20_000)});
1620
await new EditorView().closeAllEditors();
1721
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView();
1822
for (const item of [VIEWS.components, VIEWS.compRegistries, VIEWS.serverlessFunctions, VIEWS.debugSessions]) {
@@ -21,15 +25,39 @@ export function testAddCluster() {
2125
});
2226

2327
it('Page with options is shown', async function test() {
24-
this.timeout(15_000);
25-
await new Promise((res) => {setTimeout(res, 6_000)});
28+
this.timeout(70_000);
29+
//await new Promise((res) => {setTimeout(res, 15_000)});
2630
const section = await view.getContent().getSection(VIEWS.appExplorer);
27-
const buttons = await (await section.findWelcomeContent()).getButtons();
31+
const welcomeContent = await section.findWelcomeContent();
32+
const buttons = await welcomeContentButtonsAreLoaded(welcomeContent);
2833
await buttons[2].click();
2934

30-
const addClusterView = new AddClusterWebView();
35+
addClusterView = new AddClusterWebView();
36+
await webViewIsOpened(addClusterView.editorName, VSBrowser.instance.driver);
37+
3138
await addClusterView.initializeEditor();
39+
await addClusterView.checkRosaButton();
40+
await addClusterView.checkLearningButton();
41+
});
42+
43+
it('Local Cluster Page shows appropriate content', async function test() {
3244
await addClusterView.addLocalCluster();
33-
})
34-
})
45+
const localClusterPage = new LocalClusterWebViewPage();
46+
await localClusterPage.initializeEditor();
47+
await localClusterPage.checkText();
48+
await localClusterPage.checkDownloadButton();
49+
await localClusterPage.checkPathButton();
50+
await localClusterPage.clickBack();
51+
});
52+
53+
it('Developer Sandbox Page shows appropriate content', async function test() {
54+
await addClusterView.addDevSandbox();
55+
const devSandboxWebViewPage = new DevSandboxWebViewPage();
56+
await devSandboxWebViewPage.initializeEditor();
57+
await devSandboxWebViewPage.checkText();
58+
await devSandboxWebViewPage.checkLoginButton();
59+
await devSandboxWebViewPage.checkSignUpButton();
60+
await devSandboxWebViewPage.clickBack();
61+
});
62+
});
3563
}

0 commit comments

Comments
 (0)