Skip to content

Commit e7c5939

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 e7c5939

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
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 & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
isCamelVersionProductized,
3535
} from '../utils';
3636
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';
37+
import { openDropDownMenuEditorAction, selectDropDownMenuEditorAction } from './helper/Awaiters';
3838

3939
describe('Camel file editor test', function () {
4040

@@ -68,26 +68,22 @@ describe('Camel file editor test', function () {
6868
if (process.platform === "darwin"){
6969
this.skip();
7070
}
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();
71+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
72+
expect(await menu?.hasItem(CAMEL_RUN_ACTION_LABEL)).true;
73+
expect(await menu?.hasItem(CAMEL_RUN_WORKSPACE_ACTION_LABEL)).true;
74+
expect(await menu?.hasItem(CAMEL_RUN_FOLDER_ACTION_LABEL)).true;
75+
await menu?.close();
7876
});
7977

8078
it('Debug and Run actions are available', async function () {
8179
if (process.platform === "darwin"){
8280
this.skip();
8381
}
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();
82+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
83+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_ACTION_LABEL)).true;
84+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL)).true;
85+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL)).true;
86+
await menu?.close();
9187
});
9288

9389
const runActionLabels = [
@@ -101,10 +97,7 @@ describe('Camel file editor test', function () {
10197
if (process.platform === "darwin") {
10298
this.skip();
10399
}
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);
100+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", runActionLabels.label);
108101
await waitUntilTerminalHasText(driver, runActionLabels.terminalText, 2000, 120000);
109102
await killTerminal();
110103
});
@@ -124,10 +117,7 @@ describe('Camel file editor test', function () {
124117
if (process.platform === "darwin"){
125118
this.skip();
126119
}
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);
120+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", debugActionLabels.label);
131121

132122
await waitUntilTerminalHasText(driver, debugActionLabels.terminalText, 2000, 120000);
133123

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)