Skip to content

Commit 5911fbc

Browse files
committed
[test] Fix Public UI tests
Stabilizing the Public UI tests after update to vscode-extension-tester@8.23.0 - Extension test - Project test - Create Component test Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent 6bf68ea commit 5911fbc

3 files changed

Lines changed: 92 additions & 65 deletions

File tree

test/ui/suite/createComponent.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import {
1313
InputBox,
1414
NotificationType,
1515
SideBarView,
16-
ViewSection,
1716
VSBrowser,
1817
WelcomeContentButton,
19-
Workbench,
18+
Workbench
2019
} from 'vscode-extension-tester';
2120
import { notificationExists } from '../common/conditions';
2221
import { BUTTONS, INPUTS, MENUS, NOTIFICATIONS, VIEWS } from '../common/constants';
@@ -36,7 +35,6 @@ import {
3635
export function testCreateComponent(path: string) {
3736
describe('Create Component Wizard', function () {
3837
let view: SideBarView;
39-
let section: ViewSection;
4038
let button: WelcomeContentButton;
4139
let componentName: string;
4240
let dlt = true;
@@ -83,14 +81,16 @@ export function testCreateComponent(path: string) {
8381
await createComponent(createCompView);
8482

8583
componentName = 'node-js-runtime';
86-
expect(await section.findItem(componentName)).to.be.not.undefined;
84+
85+
const item = await waitForItem(componentName);
86+
expect(item).to.be.not.undefined;
8787

8888
dlt = false;
8989
});
9090

9191
it('Create component from local folder', async function test() {
9292
this.timeout(25_000);
93-
const component = await section.findItem(componentName);
93+
const component = await waitForItem(componentName);
9494
const contextMenu = await component.openContextMenu();
9595
await contextMenu.select(MENUS.deleteConfiguration);
9696

@@ -127,11 +127,10 @@ export function testCreateComponent(path: string) {
127127
setTimeout(res, 500);
128128
});
129129
await localCodeBasePage.clickCreateComponent();
130-
await new Promise((res) => {
131-
setTimeout(res, 6_000);
132-
});
133130

134-
expect(await section.findItem(componentName)).to.be.not.undefined;
131+
const item = await waitForItem(componentName);
132+
expect(item).to.be.not.undefined;
133+
135134
dlt = true;
136135
});
137136

@@ -163,7 +162,8 @@ export function testCreateComponent(path: string) {
163162

164163
//check if component is in component view
165164
componentName = 'nodejs-starter';
166-
expect(await section.findItem(componentName)).to.be.not.undefined;
165+
const item = await waitForItem(componentName);
166+
expect(item).to.be.not.undefined;
167167

168168
dlt = false;
169169
});
@@ -172,7 +172,7 @@ export function testCreateComponent(path: string) {
172172
afterEach(async function context() {
173173
this.timeout(30_000);
174174
if (componentName && dlt) {
175-
const component = await section.findItem(componentName);
175+
const component = await waitForItem(componentName);
176176
const contextMenu = await component.openContextMenu();
177177
await contextMenu.select(MENUS.deleteSourceCodeFolder);
178178
const notification = await notificationExists(
@@ -212,9 +212,6 @@ export function testCreateComponent(path: string) {
212212
await page.clearProjectFolderPath();
213213
await page.insertProjectFolderPath(path);
214214
await page.clickCreateComponentButton();
215-
await new Promise((res) => {
216-
setTimeout(res, 6_000);
217-
});
218215
}
219216

220217
async function initializeEditor(): Promise<CreateComponentWebView> {
@@ -224,13 +221,16 @@ export function testCreateComponent(path: string) {
224221
}
225222

226223
async function refreshView() {
224+
let section = await view.getContent().getSection(VIEWS.components);
225+
227226
await section.collapse();
228227
await section.expand();
228+
await new Promise(res => setTimeout(res, 1_000));
229+
230+
section = await view.getContent().getSection(VIEWS.components);
229231
const refresh = await section.getAction('Refresh Components View');
230232
await refresh.click();
231-
await new Promise((res) => {
232-
setTimeout(res, 1_000);
233-
});
233+
await new Promise((res) => setTimeout(res, 1_000));
234234
}
235235

236236
async function clickCreateComponent() {
@@ -241,7 +241,7 @@ export function testCreateComponent(path: string) {
241241
}
242242

243243
async function loadCreateComponentButton() {
244-
section = await view.getContent().getSection(VIEWS.components);
244+
const section = await view.getContent().getSection(VIEWS.components);
245245
await VSBrowser.instance.driver.wait(async () => {
246246
const buttons = await (await section.findWelcomeContent()).getButtons();
247247
for (const btn of buttons) {
@@ -252,5 +252,26 @@ export function testCreateComponent(path: string) {
252252
}
253253
}, 10_000);
254254
}
255+
256+
async function waitForItem(label, timeout = 15000) {
257+
const section = await view.getContent().getSection(VIEWS.components);
258+
259+
const start = Date.now();
260+
261+
while (Date.now() - start < timeout) {
262+
try {
263+
const item = await section.findItem(label);
264+
if (item) {
265+
return item;
266+
}
267+
} catch {
268+
// ignore transient errors
269+
}
270+
271+
await new Promise(res => setTimeout(res, 500));
272+
}
273+
274+
throw new Error(`Item "${label}" not found in section within ${timeout}ms`);
275+
}
255276
});
256277
}

test/ui/suite/extension.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,46 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import { expect } from 'chai';
7-
import { ActivityBar, ExtensionsViewItem, ExtensionsViewSection, SideBarView } from 'vscode-extension-tester';
7+
import { ActivityBar, ExtensionsViewItem, SideBarView } from 'vscode-extension-tester';
88
import * as pjson from '../../../package.json';
99
import { VIEWS } from '../common/constants';
1010

1111
export function checkExtension() {
1212
describe('Extensions view check', () => {
13-
let extView: ExtensionsViewSection;
14-
let item: ExtensionsViewItem;
15-
16-
before(async function () {
17-
this.timeout(15_000);
18-
const btn = await new ActivityBar().getViewControl(VIEWS.extensions);
19-
await btn.openView();
20-
extView = await new SideBarView().getContent().getSection(VIEWS.installed);
21-
item = await extView.findItem(`@installed ${pjson.displayName}`);
13+
14+
beforeEach(async function () {
15+
this.timeout(15000);
16+
17+
const view = await new ActivityBar().getViewControl(VIEWS.extensions);
18+
await view.openView();
19+
20+
await new Promise(res => setTimeout(res, 500));
2221
});
2322

24-
it('Openshift Toolkit is installed', () => {
23+
it('Openshift Toolkit is installed', async function () {
24+
this.timeout(30000);
25+
26+
const item = await getItem();
2527
expect(item).not.undefined;
2628
});
2729

28-
it('Openshift toolkit has the correct attributes', async function() {
29-
this.timeout(15_000)
30-
let version: string;
31-
let author: string;
32-
let desc: string;
33-
try{
34-
version = await item.getVersion();
35-
author = await item.getAuthor();
36-
desc = await item.getDescription();
37-
} catch {
38-
await new Promise(res => setTimeout(res, 5_000));
39-
version = await item.getVersion();
40-
author = await item.getAuthor();
41-
desc = await item.getDescription();
42-
}
30+
it('Openshift toolkit has the correct attributes', async function () {
31+
this.timeout(30000);
32+
33+
const item = await getItem();
34+
35+
const version = await item.getVersion();
36+
const author = await item.getAuthor();
37+
const desc = await item.getDescription();
4338

4439
expect(version).equals(pjson.version);
4540
expect(author).equals(pjson.author);
4641
expect(desc).equals(pjson.description);
4742
});
43+
44+
async function getItem(): Promise<ExtensionsViewItem> {
45+
const section = await new SideBarView().getContent().getSection(VIEWS.installed);
46+
return await section.findItem(`@installed ${pjson.displayName}`) as ExtensionsViewItem;
47+
}
4848
});
49-
}
49+
}

test/ui/suite/project.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import {
7-
SideBarView,
8-
ViewSection,
7+
ActivityBar,
98
EditorView,
109
InputBox,
11-
ActivityBar,
12-
NotificationType,
13-
Workbench,
10+
SideBarView,
1411
TreeItem,
1512
VSBrowser,
16-
before,
17-
beforeEach,
13+
ViewSection,
14+
Workbench,
1815
after,
16+
before,
17+
beforeEach
1918
} from 'vscode-extension-tester';
19+
import { activateCommand } from '../common/command-activator';
2020
import { itemExists, notificationExists } from '../common/conditions';
2121
import { INPUTS, MENUS, NOTIFICATIONS, VIEWS } from '../common/constants';
22-
import { activateCommand } from '../common/command-activator';
2322

2423
export function projectTest(isOpenshiftCluster: boolean) {
2524
describe('Work with project', function () {
@@ -33,25 +32,25 @@ export function projectTest(isOpenshiftCluster: boolean) {
3332
const deleteProject = isOpenshiftCluster ? MENUS.deleteProject : MENUS.deleteNamespace;
3433

3534
let view: SideBarView;
36-
let explorer: ViewSection;
3735

3836
let projectName: string;
3937
let anotherProjectName: string;
4038

4139
before(async function () {
4240
this.timeout(10_000);
4341
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView();
44-
explorer = await view.getContent().getSection(VIEWS.appExplorer);
42+
try {
43+
const notifications = await new Workbench().getNotifications();
44+
for (const n of notifications) {
45+
try { await n.dismiss(); } catch { /* Ignore */ }
46+
}
47+
} catch { /* Ignore */ }
48+
const explorer = await getExplorer();
4549
await explorer.expand();
4650
await itemExists(clusterName, explorer);
4751
});
4852

4953
beforeEach(async function () {
50-
const notificationCenter = await new Workbench().openNotificationsCenter();
51-
const notifications = await notificationCenter.getNotifications(NotificationType.Any);
52-
if (notifications.length > 0) {
53-
await notificationCenter.close();
54-
}
5554
await new EditorView().closeAllEditors();
5655
});
5756

@@ -65,12 +64,13 @@ export function projectTest(isOpenshiftCluster: boolean) {
6564
await input.setText(anotherProjectName);
6665
await input.confirm();
6766

67+
const explorer = await getExplorer();
6868
(await itemExists(anotherProjectName, explorer)) as TreeItem;
6969
});
7070

7171
it('Create a new project', async function () {
7272
this.timeout(30_000);
73-
const clusterItem = (await explorer.findItem(clusterName)) as TreeItem;
73+
const clusterItem = (await (await getExplorer()).findItem(clusterName)) as TreeItem;
7474
await clusterItem.expand();
7575
const contextMenu = await clusterItem.openContextMenu();
7676
await contextMenu.select(newProject);
@@ -84,14 +84,15 @@ export function projectTest(isOpenshiftCluster: boolean) {
8484
await input.setText(projectName);
8585
await input.confirm();
8686

87+
const explorer = await getExplorer();
8788
await itemExists(projectName, explorer);
8889
});
8990

9091
it('Project can be changed', async function () {
9192
this.timeout(30_000);
9293
anotherProjectName = getProjectName();
9394

94-
const clusterItem = (await explorer.findItem(clusterName)) as TreeItem;
95+
const clusterItem = (await (await getExplorer()).findItem(clusterName)) as TreeItem;
9596
await clusterItem.expand();
9697
const contextMenu = await clusterItem.openContextMenu();
9798
await contextMenu.select(newProject);
@@ -100,6 +101,7 @@ export function projectTest(isOpenshiftCluster: boolean) {
100101
await input.setText(anotherProjectName);
101102
await input.confirm();
102103

104+
let explorer = await getExplorer();
103105
const item = (await itemExists(anotherProjectName, explorer)) as TreeItem;
104106

105107
const changeActiveProjectButton = await item.getActionButton(changeProject);
@@ -112,15 +114,15 @@ export function projectTest(isOpenshiftCluster: boolean) {
112114
await input.setText(projectName);
113115
await input.confirm();
114116

117+
explorer = await getExplorer();
115118
await itemExists(projectName, explorer);
116119
});
117120

118121
it('Delete a project', async function () {
119122
this.timeout(30_000);
120-
const projectItem = await explorer.findItem(projectName);
121-
const contextMenu = await projectItem.openContextMenu();
122123

123-
await contextMenu.select(deleteProject);
124+
const projectItem = await (await getExplorer()).findItem(projectName);
125+
const contextMenu = await projectItem.openContextMenu();
124126

125127
await contextMenu.select(deleteProject);
126128

@@ -156,5 +158,9 @@ export function projectTest(isOpenshiftCluster: boolean) {
156158
function getProjectName() {
157159
return `project${Math.floor(Math.random() * 100)}`;
158160
}
161+
162+
async function getExplorer(): Promise<ViewSection> {
163+
return await view.getContent().getSection(VIEWS.appExplorer);
164+
}
159165
});
160166
}

0 commit comments

Comments
 (0)