Skip to content

Commit 29c89df

Browse files
Lukas Grossmannvrubezhny
Lukas Grossmann
authored andcommitted
Improving stability for Create Component and Application explorer UI tests
Signed-off-by: Lukas Grossmann <[email protected]>
1 parent 2463f69 commit 29c89df

File tree

4 files changed

+108
-45
lines changed

4 files changed

+108
-45
lines changed

test/ui/common/conditions.ts

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export async function welcomeContentButtonsAreLoaded(welcomeContentSection: Welc
9191
}, timeout);
9292
}
9393

94+
export async function welcomeContentIsLoaded(viewSection: ViewSection, timeout = 60_000) {
95+
return viewSection.getDriver().wait(async () => {
96+
const welcomeContent = await viewSection.findWelcomeContent();
97+
if(welcomeContent) {
98+
return welcomeContent
99+
}
100+
}, timeout);
101+
}
102+
94103
export async function webViewIsOpened(name: string, driver: WebDriver, timeout = 10_000) {
95104
return driver.wait(async () => {
96105
try {

test/ui/common/ui/webview/newComponentWebViewEditor.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class SetNameAndFolderPage extends WebViewForm {
7272
public async clearProjectFolderPath(): Promise<void> {
7373
await this.enterWebView(async (webView) => {
7474
const pathField = await this.getProjectFolderPathField(webView);
75-
const controlKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL
75+
const controlKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL;
7676
await pathField.sendKeys(`${controlKey} ${'a'}`);
7777
await pathField.sendKeys(Key.DELETE);
7878
});
@@ -82,7 +82,7 @@ export class SetNameAndFolderPage extends WebViewForm {
8282
await this.enterWebView(async (webView) => {
8383
const button = await this.getSelectFolderButton(webView);
8484
await button.click();
85-
})
85+
});
8686
}
8787

8888
public async clickCreateComponentButton(): Promise<void> {
@@ -106,15 +106,16 @@ export class SetNameAndFolderPage extends WebViewForm {
106106
}
107107

108108
abstract class Page extends WebViewForm {
109+
109110
public constructor() {
110-
super('Create Component')
111+
super('Create Component');
111112
}
112113

113114
public async clickNextButton(): Promise<void> {
114115
await this.enterWebView(async (webView) => {
115116
const button = await this.getNextButton(webView);
116117
await button.click();
117-
})
118+
});
118119
}
119120

120121
/**
@@ -123,7 +124,7 @@ abstract class Page extends WebViewForm {
123124
public async clickSelectDifferentDevfileButton(): Promise<void> {
124125
await this.enterWebView(async (webView) => {
125126
const button = await this.getSelectDifferentDevfileButton(webView);
126-
await button.click()
127+
await button.click();
127128
});
128129
}
129130

@@ -149,7 +150,7 @@ export class GitProjectPage extends Page {
149150
public async insertGitLink(link: string): Promise<void> {
150151
await this.enterWebView(async (webView) => {
151152
const linkField = await this.getGitRepositoryLinkField(webView);
152-
await linkField.sendKeys(link)
153+
await linkField.sendKeys(link);
153154
});
154155
}
155156

@@ -158,11 +159,24 @@ export class GitProjectPage extends Page {
158159
*/
159160
public async clickContinueButton(): Promise<void> {
160161
await this.enterWebView(async (webView) => {
161-
const button = await this.getContinueButton(webView);
162-
await button.click()
162+
const button = await this.continueButtonExists(webView);
163+
await button.click();
163164
});
164165
}
165166

167+
private async continueButtonExists(webView: WebView, timeout = 60_000): Promise<WebElement> {
168+
return webView.getDriver().wait(async () => {
169+
try {
170+
const button = await this.getContinueButton(webView);
171+
if (button) {
172+
return button;
173+
}
174+
} catch (err) {
175+
return null;
176+
}
177+
}, timeout);
178+
}
179+
166180
private async getContinueButton(webView: WebView): Promise<WebElement> {
167181
return await webView.findWebElement(By.xpath('//button[contains(text(), "CONTINUE WITH THIS DEVFILE")]'));
168182
}
@@ -173,28 +187,29 @@ export class GitProjectPage extends Page {
173187
}
174188

175189
export class LocalCodeBasePage extends Page {
190+
176191
public constructor() {
177192
super();
178193
}
179194

180195
public async insertComponentName(name: string): Promise<void> {
181196
await this.enterWebView(async (webView) => {
182197
const nameField = await this.getComponentNameField(webView);
183-
await nameField.sendKeys(name)
198+
await nameField.sendKeys(name);
184199
});
185200
}
186201

187202
public async clickSelectFolderButton(): Promise<void> {
188203
await this.enterWebView(async (webView) => {
189204
const button = await this.getSelectFolderButton(webView);
190-
await button.click()
205+
await button.click();
191206
});
192207
}
193208

194209
public async clickCreateComponent(): Promise<void> {
195210
await this.enterWebView(async (webView) => {
196211
const button = await this.getCreateComponentButton(webView);
197-
await button.click()
212+
await button.click();
198213
});
199214
}
200215

test/ui/suite/createComponent.ts

+70-33
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,58 @@
55
import * as fs from 'fs-extra';
66
import * as pth from 'path';
77
import { expect } from 'chai';
8-
import { ActivityBar, EditorView, InputBox, NotificationType, SideBarView, ViewSection, WelcomeContentButton, Workbench } from 'vscode-extension-tester';
8+
import {
9+
ActivityBar,
10+
EditorView,
11+
InputBox,
12+
NotificationType,
13+
SideBarView,
14+
ViewSection,
15+
WelcomeContentButton,
16+
Workbench,
17+
} from 'vscode-extension-tester';
918
import { VIEWS, BUTTONS } from '../common/constants';
10-
import { CreateComponentWebView, GitProjectPage, LocalCodeBasePage, SetNameAndFolderPage } from '../common/ui/webview/newComponentWebViewEditor';
11-
import { RegistryWebViewDevfileWindow, RegistryWebViewEditor } from '../common/ui/webview/registryWebViewEditor';
19+
import {
20+
CreateComponentWebView,
21+
GitProjectPage,
22+
LocalCodeBasePage,
23+
SetNameAndFolderPage,
24+
} from '../common/ui/webview/newComponentWebViewEditor';
25+
import {
26+
RegistryWebViewDevfileWindow,
27+
RegistryWebViewEditor,
28+
} from '../common/ui/webview/registryWebViewEditor';
1229
import { afterEach } from 'mocha';
1330
import { collapse } from '../common/overdrives';
1431

1532
//TODO: Add more checks for different elements
1633
export function testCreateComponent(path: string) {
1734
describe('Create Component Wizard', function () {
18-
1935
let view: SideBarView;
2036
let section: ViewSection;
21-
let button: WelcomeContentButton
22-
let componentName: string
37+
let button: WelcomeContentButton;
38+
let componentName: string;
2339
let dlt = true;
2440

2541
before(async function context() {
26-
this.timeout(10_000)
42+
this.timeout(10_000);
2743
await new EditorView().closeAllEditors();
2844
fs.ensureDirSync(path, 0o6777);
2945
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView();
30-
for (const item of [VIEWS.appExplorer, VIEWS.compRegistries, VIEWS.serverlessFunctions, VIEWS.debugSessions]) {
31-
await collapse(await view.getContent().getSection(item))
46+
for (const item of [
47+
VIEWS.appExplorer,
48+
VIEWS.compRegistries,
49+
VIEWS.serverlessFunctions,
50+
VIEWS.debugSessions,
51+
]) {
52+
await collapse(await view.getContent().getSection(item));
3253
}
3354
await loadCreateComponentButton();
3455
});
3556

3657
it('Shows default actions when no component exists', function test() {
37-
if(!button) {
38-
expect.fail('No Create Component button found')
58+
if (!button) {
59+
expect.fail('No Create Component button found');
3960
}
4061
});
4162

@@ -51,20 +72,22 @@ export function testCreateComponent(path: string) {
5172
await gitPage.initializeEditor();
5273
await gitPage.insertGitLink('https://github.com/odo-devfiles/nodejs-ex');
5374
await gitPage.clickNextButton();
54-
await new Promise((res) => { setTimeout(res, 1_500)});
75+
await new Promise((res) => {
76+
setTimeout(res, 1_500);
77+
});
5578
await gitPage.clickContinueButton();
5679

57-
await createComponent(createCompView)
80+
await createComponent(createCompView);
5881

5982
componentName = 'node-js-runtime';
6083
expect(await section.findItem(componentName)).to.be.not.undefined;
6184

62-
dlt = false
85+
dlt = false;
6386
});
6487

6588
it('Create component from local folder', async function test() {
66-
this.timeout(25_000)
67-
fs.rmSync(pth.join(path, componentName, 'devfile.yaml'), {force: true});
89+
this.timeout(25_000);
90+
fs.rmSync(pth.join(path, componentName, 'devfile.yaml'), { force: true });
6891
await refreshView();
6992
await loadCreateComponentButton();
7093
await clickCreateComponent();
@@ -74,20 +97,24 @@ export function testCreateComponent(path: string) {
7497

7598
const localCodeBasePage = new LocalCodeBasePage();
7699
await localCodeBasePage.initializeEditor();
77-
await localCodeBasePage.insertComponentName(componentName)
100+
await localCodeBasePage.insertComponentName(componentName);
78101
await localCodeBasePage.clickSelectFolderButton();
79102

80103
const input = await InputBox.create();
81104
await input.setText(pth.join(path, componentName));
82105
await input.confirm();
83106

84107
await localCodeBasePage.clickNextButton();
85-
await new Promise((res) => { setTimeout(res, 500); });
108+
await new Promise((res) => {
109+
setTimeout(res, 500);
110+
});
86111
await localCodeBasePage.clickCreateComponent();
87-
await new Promise((res) => { setTimeout(res, 6_000); });
112+
await new Promise((res) => {
113+
setTimeout(res, 6_000);
114+
});
88115

89116
expect(await section.findItem(componentName)).to.be.not.undefined;
90-
dlt = true
117+
dlt = true;
91118
});
92119

93120
it('Create component from template project', async function test() {
@@ -104,35 +131,36 @@ export function testCreateComponent(path: string) {
104131
const devfileView = new RegistryWebViewEditor(createCompView.editorName);
105132
await devfileView.initializeEditor();
106133
await devfileView.selectRegistryStack('Node.js Runtime');
107-
await new Promise((res) => { setTimeout(res, 500); });
134+
await new Promise((res) => {
135+
setTimeout(res, 500);
136+
});
108137

109138
//Initialize stack window and click Use Devfile
110139
const devFileWindow = new RegistryWebViewDevfileWindow(createCompView.editorName);
111140
await devFileWindow.initializeEditor();
112141
await devFileWindow.useDevfile();
113142

114143
//Initialize next page, fill out path and select create component
115-
await createComponent(createCompView)
144+
await createComponent(createCompView);
116145

117146
//check if component is in component view
118147
componentName = 'nodejs-starter';
119148
expect(await section.findItem(componentName)).to.be.not.undefined;
120-
121149
});
122150

123151
//Delete the component using file system
124152
afterEach(async function context() {
125-
this.timeout(30_000)
126-
if(componentName && dlt) {
127-
fs.rmSync(pth.join(path, componentName), {recursive: true, force: true});
153+
this.timeout(30_000);
154+
if (componentName && dlt) {
155+
fs.rmSync(pth.join(path, componentName), { recursive: true, force: true });
128156
componentName = undefined;
129157
await refreshView();
130158
await loadCreateComponentButton();
131159
}
132160
await new EditorView().closeAllEditors();
133161
const notificationCenter = await new Workbench().openNotificationsCenter();
134162
const notifications = await notificationCenter.getNotifications(NotificationType.Any);
135-
if(notifications.length > 0) {
163+
if (notifications.length > 0) {
136164
await notificationCenter.close();
137165
}
138166
});
@@ -143,11 +171,14 @@ export function testCreateComponent(path: string) {
143171
await prompt.confirm();
144172
await prompt.setText('node-js-runtime');
145173
await prompt.confirm();
174+
await new Promise((res) => {
175+
setTimeout(res, 2_500);
176+
});
146177
prompt = await new Workbench().openCommandPrompt();
147178
await prompt.setText('>Workspaces: Remove Folder From Workspace...');
148179
await prompt.confirm();
149180
await prompt.setText('nodejs-starter');
150-
await prompt.confirm()
181+
await prompt.confirm();
151182
});
152183

153184
async function createComponent(createCompView: CreateComponentWebView): Promise<void> {
@@ -156,7 +187,9 @@ export function testCreateComponent(path: string) {
156187
await page.clearProjectFolderPath();
157188
await page.insertProjectFolderPath(path);
158189
await page.clickCreateComponentButton();
159-
await new Promise((res => {setTimeout(res, 6_000)}))
190+
await new Promise((res) => {
191+
setTimeout(res, 6_000);
192+
});
160193
}
161194

162195
async function initializeEditor(): Promise<CreateComponentWebView> {
@@ -170,19 +203,23 @@ export function testCreateComponent(path: string) {
170203
await section.expand();
171204
const refresh = await section.getAction('Refresh Components View');
172205
await refresh.click();
173-
await new Promise((res => {setTimeout(res, 1_000)}));
206+
await new Promise((res) => {
207+
setTimeout(res, 1_000);
208+
});
174209
}
175210

176211
async function clickCreateComponent() {
177212
await button.click();
178-
await new Promise((res) => { setTimeout(res, 3_000); });
213+
await new Promise((res) => {
214+
setTimeout(res, 3_000);
215+
});
179216
}
180217

181218
async function loadCreateComponentButton() {
182219
section = await view.getContent().getSection(VIEWS.components);
183220
const buttons = await (await section.findWelcomeContent()).getButtons();
184-
for(const btn of buttons) {
185-
if(await btn.getTitle() === BUTTONS.newComponent) {
221+
for (const btn of buttons) {
222+
if ((await btn.getTitle()) === BUTTONS.newComponent) {
186223
button = btn;
187224
}
188225
}

test/ui/suite/openshift.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { expect } from 'chai';
66
import { ActivityBar, CustomTreeSection, SideBarView, ViewSection, WelcomeContentSection, Workbench } from 'vscode-extension-tester';
77
import { BUTTONS, VIEWS } from '../common/constants';
88
import { collapse } from '../common/overdrives';
9+
import { welcomeContentButtonsAreLoaded, welcomeContentIsLoaded } from '../common/conditions';
910

1011
export function checkOpenshiftView() {
1112
describe('OpenShift View', function() {
@@ -36,14 +37,15 @@ export function checkOpenshiftView() {
3637
before(async function() {
3738
explorer = await view.getContent().getSection(VIEWS.appExplorer);
3839
await explorer.expand();
39-
welcome = await explorer.findWelcomeContent();
40+
welcome = await welcomeContentIsLoaded(explorer);
4041

4142
for (const item of [VIEWS.components, VIEWS.compRegistries, VIEWS.serverlessFunctions, VIEWS.debugSessions]) {
4243
await (await view.getContent().getSection(item)).collapse();
4344
}
4445
});
4546

4647
it('shows welcome content when not logged in', async function() {
48+
await welcomeContentButtonsAreLoaded(welcome);
4749
expect(welcome).not.undefined;
4850
const description = (await welcome.getTextSections()).join('');
4951
expect(description).not.empty;

0 commit comments

Comments
 (0)