Skip to content

Commit 81f0ebb

Browse files
committed
Enclose the whole interaction with the EditorAction menu in the
conditional wait to avoid having some stale reference when trying to click on them after we found them. Signed-off-by: Aurélien Pupier <[email protected]>
1 parent 29964d8 commit 81f0ebb

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

src/ui-test/tests/actions.requirements.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import path from "path";
19-
import { ActivityBar, EditorActionDropdown, EditorView, SideBarView, VSBrowser, WebDriver, Workbench } from "vscode-extension-tester";
19+
import { ActivityBar, EditorView, SideBarView, VSBrowser, WebDriver, Workbench } from "vscode-extension-tester";
2020
import { CAMEL_ROUTE_YAML_WITH_SPACE, CAMEL_RUN_ACTION_LABEL, CAMEL_RUN_DEBUG_ACTION_LABEL, CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL, CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL, CAMEL_RUN_FOLDER_ACTION_LABEL, CAMEL_RUN_WORKSPACE_ACTION_LABEL } from "../variables";
2121
import { expect } from "chai";
2222
import { notificationCenterContains, waitUntilNotificationShows } from "../utils";
23-
import { actionAvailable } from './helper/Awaiters';
23+
import { selectDropDownMenuEditorAction } from './helper/Awaiters';
2424

2525
describe('Check actions requirements to run/debug', function () {
2626
this.timeout(90000);
@@ -77,10 +77,7 @@ describe('Check actions requirements to run/debug', function () {
7777
});
7878

7979
async function clickButtonAndVerifyNotification(actionLabel: string) {
80-
await actionAvailable(editorView, "Run or Debug...");
81-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
82-
const menu = await action.open();
83-
await menu.select(actionLabel);
80+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", actionLabel);
8481
await waitUntilNotificationShows(driver, NOTIFICATION_TEXT);
8582
expect(await notificationCenterContains(NOTIFICATION_TEXT)).to.be.true;
8683
const center = await new Workbench().openNotificationsCenter();

src/ui-test/tests/deploy.kubernetes.run.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import { resolve, join } from 'node:path';
1818
import {
1919
after,
2020
before,
21-
EditorAction,
2221
EditorView,
2322
VSBrowser,
2423
} from 'vscode-extension-tester';
2524
import { killTerminal, waitUntilTerminalHasText } from '../utils';
2625
import { CAMEL_ROUTE_YAML_WITH_SPACE } from '../variables';
27-
import { actionAvailable } from './helper/Awaiters';
26+
import { clickOnEditorAction } from './helper/Awaiters';
2827

2928
/**
3029
* Note: OC login needs to be done before executing this test for deployment into OpenShift
@@ -52,10 +51,8 @@ describe('Camel standalone file deployment using Camel JBang Kubernetes Run', fu
5251

5352
it('Deploy integration to OpenShift or Kubernetes (Minikube)', async function () {
5453
await VSBrowser.instance.driver.sleep(500);
55-
await actionAvailable(editorView, 'Deploy Integration with Apache Camel Kubernetes Run');
56-
const action = (await editorView.getAction('Deploy Integration with Apache Camel Kubernetes Run')) as EditorAction;
57-
await action.click();
58-
await waitUntilTerminalHasText(action.getDriver(), ['Hello Camel from'], 10_000, 900_000);
54+
await clickOnEditorAction(editorView, 'Deploy Integration with Apache Camel Kubernetes Run');
55+
await waitUntilTerminalHasText(VSBrowser.instance.driver, ['Hello Camel from'], 10_000, 900_000);
5956
});
6057

6158
});

src/ui-test/tests/editor.actions.test.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as path from 'path';
1919
import {
2020
ActivityBar,
2121
BottomBarPanel,
22-
EditorActionDropdown,
2322
EditorView,
2423
SideBarView,
2524
VSBrowser,
@@ -34,7 +33,7 @@ import {
3433
isCamelVersionProductized,
3534
} from '../utils';
3635
import { CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL, CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL, CAMEL_RUN_FOLDER_ACTION_LABEL, CAMEL_RUN_WORKSPACE_ACTION_LABEL, TOP_ROUTE_1 } from '../variables';
37-
import { actionAvailable } from './helper/Awaiters';
36+
import { openDropDownMenuEditorAction, selectDropDownMenuEditorAction } from './helper/Awaiters';
3837

3938
describe('Camel file editor test', function () {
4039

@@ -68,26 +67,22 @@ describe('Camel file editor test', function () {
6867
if (process.platform === "darwin"){
6968
this.skip();
7069
}
71-
await actionAvailable(editorView, "Run or Debug...");
72-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
73-
const menu = await action.open();
74-
expect(await menu.hasItem(CAMEL_RUN_ACTION_LABEL)).true;
75-
expect(await menu.hasItem(CAMEL_RUN_WORKSPACE_ACTION_LABEL)).true;
76-
expect(await menu.hasItem(CAMEL_RUN_FOLDER_ACTION_LABEL)).true;
77-
await menu.close();
70+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
71+
expect(await menu?.hasItem(CAMEL_RUN_ACTION_LABEL)).true;
72+
expect(await menu?.hasItem(CAMEL_RUN_WORKSPACE_ACTION_LABEL)).true;
73+
expect(await menu?.hasItem(CAMEL_RUN_FOLDER_ACTION_LABEL)).true;
74+
await menu?.close();
7875
});
7976

8077
it('Debug and Run actions are available', async function () {
8178
if (process.platform === "darwin"){
8279
this.skip();
8380
}
84-
await actionAvailable(editorView, "Run or Debug...");
85-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
86-
const menu = await action.open();
87-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_ACTION_LABEL)).true;
88-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL)).true;
89-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL)).true;
90-
await menu.close();
81+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
82+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_ACTION_LABEL)).true;
83+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL)).true;
84+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL)).true;
85+
await menu?.close();
9186
});
9287

9388
const runActionLabels = [
@@ -101,10 +96,7 @@ describe('Camel file editor test', function () {
10196
if (process.platform === "darwin") {
10297
this.skip();
10398
}
104-
await actionAvailable(editorView, "Run or Debug...");
105-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
106-
const menu = await action.open();
107-
await menu.select(runActionLabels.label);
99+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", runActionLabels.label);
108100
await waitUntilTerminalHasText(driver, runActionLabels.terminalText, 2000, 120000);
109101
await killTerminal();
110102
});
@@ -124,10 +116,7 @@ describe('Camel file editor test', function () {
124116
if (process.platform === "darwin"){
125117
this.skip();
126118
}
127-
await actionAvailable(editorView, "Run or Debug...");
128-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
129-
const menu = await action.open();
130-
await menu.select(debugActionLabels.label);
119+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", debugActionLabels.label);
131120

132121
await waitUntilTerminalHasText(driver, debugActionLabels.terminalText, 2000, 120000);
133122

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
import waitUntil from 'async-wait-until';
2-
import { EditorView } from 'vscode-extension-tester';
2+
import { ContextMenu, EditorView } from 'vscode-extension-tester';
33

44

5-
export async function actionAvailable(editorView: EditorView, actionLabel: string) {
5+
export async function clickOnEditorAction(editorView: EditorView, actionLabel: string) {
66
await waitUntil(async () => {
77
try {
8-
return await editorView.getAction(actionLabel) !== undefined;
8+
const action = await editorView.getAction(actionLabel);
9+
if (action !== undefined) {
10+
await action.click();
11+
return true;
12+
} else {
13+
return false;
14+
}
915
} catch {
1016
return false;
1117
}
1218
});
1319
}
20+
21+
export async function openDropDownMenuEditorAction(editorView: EditorView, actionLabel: string) :Promise<ContextMenu | undefined>{
22+
let contextMenu : ContextMenu | undefined = undefined;
23+
await waitUntil(async () => {
24+
try {
25+
const action = await editorView.getAction(actionLabel);
26+
if (action !== undefined) {
27+
contextMenu = await action.open();
28+
return true;
29+
} else {
30+
return false;
31+
}
32+
} catch {
33+
return false;
34+
}
35+
});
36+
return contextMenu;
37+
}
38+
39+
export async function selectDropDownMenuEditorAction(editorView: EditorView, actionLabel: string, subActionLabel: string) :Promise<ContextMenu | undefined>{
40+
let contextMenu : ContextMenu | undefined = undefined;
41+
await waitUntil(async () => {
42+
try {
43+
const action = await editorView.getAction(actionLabel);
44+
if (action !== undefined) {
45+
contextMenu = await action.open();
46+
await contextMenu.select(subActionLabel);
47+
return true;
48+
} else {
49+
return false;
50+
}
51+
} catch {
52+
return false;
53+
}
54+
});
55+
return contextMenu;
56+
}

0 commit comments

Comments
 (0)