Skip to content

Commit f468d9f

Browse files
authored
[WIP] Fix e2e tests (#1812)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent 5563d38 commit f468d9f

File tree

9 files changed

+103
-69
lines changed

9 files changed

+103
-69
lines changed

packages/databricks-vscode/src/test/e2e/auth.e2e.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from "node:assert";
22
import {
33
dismissNotifications,
4+
getActionButton,
45
waitForInput,
56
getViewSection,
67
waitForLogin,
@@ -70,8 +71,12 @@ describe("Configure Databricks Extension", async function () {
7071
const items = await section.getVisibleItems();
7172
for (const item of items) {
7273
const label = await item.getLabel();
74+
console.log(
75+
"Looking for signin button, got item:",
76+
await (await item.elem).getHTML()
77+
);
7378
if (label.toLowerCase().includes("auth type")) {
74-
return item.getActionButton("Sign in");
79+
return getActionButton(item, "Sign in");
7580
}
7681
}
7782
},

packages/databricks-vscode/src/test/e2e/deploy_and_run_job.e2e.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import assert from "node:assert";
22
import {
33
dismissNotifications,
4+
getActionButton,
45
getUniqueResourceName,
56
getViewSection,
7+
selectOutputChannel,
68
waitForDeployment,
79
waitForLogin,
810
waitForTreeItems,
@@ -65,7 +67,7 @@ describe("Deploy and run job", async function () {
6567

6668
it("should deploy and run the current job", async () => {
6769
const outputView = await workbench.getBottomBar().openOutputView();
68-
await outputView.selectChannel("Databricks Bundle Logs");
70+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
6971
await outputView.clearText();
7072

7173
const jobItem = await getResourceViewItem(
@@ -75,7 +77,8 @@ describe("Deploy and run job", async function () {
7577
);
7678
assert(jobItem, `Job ${jobName} not found in resource explorer`);
7779

78-
const deployAndRunButton = await jobItem.getActionButton(
80+
const deployAndRunButton = await getActionButton(
81+
jobItem,
7982
"Deploy the bundle and run the job"
8083
);
8184
assert(deployAndRunButton, "Deploy and run button not found");

packages/databricks-vscode/src/test/e2e/deploy_and_run_pipeline.e2e.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import assert from "node:assert";
22
import {
33
dismissNotifications,
4+
getActionButton,
45
getViewSection,
6+
selectOutputChannel,
57
waitForDeployment,
68
waitForLogin,
79
waitForTreeItems,
@@ -62,7 +64,7 @@ describe("Deploy and run pipeline", async function () {
6264

6365
it("should deploy and run the current pipeline", async () => {
6466
const outputView = await workbench.getBottomBar().openOutputView();
65-
await outputView.selectChannel("Databricks Bundle Logs");
67+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
6668
await outputView.clearText();
6769

6870
const pipelineItem = await getResourceViewItem(
@@ -75,13 +77,14 @@ describe("Deploy and run pipeline", async function () {
7577
`Pipeline ${pipelineName} not found in resource explorer`
7678
);
7779

78-
const deployAndRunButton = await pipelineItem.getActionButton(
80+
const deployAndRunButton = await getActionButton(
81+
pipelineItem,
7982
"Deploy the bundle and run the pipeline"
8083
);
8184
assert(deployAndRunButton, "Deploy and run button not found");
8285
await deployAndRunButton.elem.click();
8386

84-
await waitForDeployment();
87+
await waitForDeployment(outputView);
8588

8689
await waitForRunStatus(
8790
resourceExplorerView,

packages/databricks-vscode/src/test/e2e/destroy.e2e.ts

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
dismissNotifications,
44
getUniqueResourceName,
55
getViewSection,
6+
selectOutputChannel,
67
waitForLogin,
78
waitForTreeItems,
89
} from "./utils/commonUtils.ts";
@@ -71,42 +72,33 @@ describe("Deploy and destroy", async function () {
7172
.replaceAll(/[^a-zA-Z0-9]/g, "_")}]`;
7273

7374
const outputView = await workbench.getBottomBar().openOutputView();
74-
await outputView.selectChannel("Databricks Bundle Logs");
75+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
7576
await outputView.clearText();
7677

7778
await browser.executeWorkbench(async (vscode) => {
7879
await vscode.commands.executeCommand("databricks.bundle.deploy");
7980
});
81+
82+
await browser.executeWorkbench(async (vscode) => {
83+
await vscode.commands.executeCommand(
84+
"workbench.panel.output.focus"
85+
);
86+
});
87+
88+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
89+
8090
console.log("Waiting for deployment to finish");
81-
// Wait for the deployment to finish
8291
await browser.waitUntil(
8392
async () => {
8493
try {
85-
await browser.executeWorkbench(async (vscode) => {
86-
await vscode.commands.executeCommand(
87-
"workbench.panel.output.focus"
88-
);
89-
});
90-
const outputView = await workbench
91-
.getBottomBar()
92-
.openOutputView();
93-
94-
if (
95-
(await outputView.getCurrentChannel()) !==
96-
"Databricks Bundle Logs"
97-
) {
98-
await outputView.selectChannel(
99-
"Databricks Bundle Logs"
100-
);
101-
}
102-
10394
const logs = (await outputView.getText()).join("");
10495
console.log(logs);
10596
return (
10697
logs.includes("Bundle deployed successfully") &&
10798
logs.includes("Bundle configuration refreshed")
10899
);
109100
} catch (e) {
101+
console.log("Error waiting for deployment to finish:", e);
110102
return false;
111103
}
112104
},
@@ -135,29 +127,19 @@ describe("Deploy and destroy", async function () {
135127
);
136128
});
137129

130+
await browser.executeWorkbench(async (vscode) => {
131+
await vscode.commands.executeCommand(
132+
"workbench.panel.output.focus"
133+
);
134+
});
135+
136+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
137+
138138
console.log("Waiting for bundle to destroy");
139139
// Wait for status to reach success
140140
await browser.waitUntil(
141141
async () => {
142142
try {
143-
await browser.executeWorkbench(async (vscode) => {
144-
await vscode.commands.executeCommand(
145-
"workbench.panel.output.focus"
146-
);
147-
});
148-
const outputView = await workbench
149-
.getBottomBar()
150-
.openOutputView();
151-
152-
if (
153-
(await outputView.getCurrentChannel()) !==
154-
"Databricks Bundle Logs"
155-
) {
156-
await outputView.selectChannel(
157-
"Databricks Bundle Logs"
158-
);
159-
}
160-
161143
const logs = (await outputView.getText()).join("");
162144
console.log(logs);
163145
return (

packages/databricks-vscode/src/test/e2e/refresh_resource_explorer_on_yml_change.e2e.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {CustomTreeSection} from "wdio-vscode-service";
33
import {
44
dismissNotifications,
55
getViewSection,
6+
selectOutputChannel,
67
waitForLogin,
78
} from "./utils/commonUtils.ts";
89
import {
@@ -78,7 +79,8 @@ describe("Automatically refresh resource explorer", async function () {
7879
const outputView = await (await browser.getWorkbench())
7980
.getBottomBar()
8081
.openOutputView();
81-
await outputView.selectChannel("Databricks Bundle Logs");
82+
83+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
8284

8385
const jobDef = await createProjectWithJob(
8486
projectName,

packages/databricks-vscode/src/test/e2e/run_dbconnect.ucws.e2e.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,15 @@ describe("Run files on serverless compute", async function () {
198198

199199
// Install dependencies from the requirements.txt
200200
const dependenciesInput = await waitForInput();
201-
await dependenciesInput.toggleAllQuickPicks(true);
201+
try {
202+
await dependenciesInput.toggleAllQuickPicks(true);
203+
} catch (e) {
204+
console.log(
205+
"Failed to toggle all quick picks, moving on. Error:",
206+
e
207+
);
208+
}
202209
await dependenciesInput.confirm();
203-
204210
await waitForNotification("The following environment is selected");
205211
await waitForNotification("Databricks Connect", "Install");
206212

packages/databricks-vscode/src/test/e2e/run_files.e2e.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,22 @@ describe("Run files", async function () {
5151
await executeCommandWhenAvailable("Databricks: Upload and Run File");
5252
await browser.waitUntil(async () => {
5353
const notifications = await workbench.getNotifications();
54+
console.log("Notifications:", notifications.length);
5455
for (const notification of notifications) {
5556
const message = await notification.getMessage();
57+
console.log("Message:", message);
5658
if (message.includes("Uploading bundle assets")) {
57-
await notification.takeAction("Cancel");
59+
const elements = await notification.actions$.$$(
60+
notification.locators.action
61+
);
62+
console.log("Elements:", elements.length);
63+
for (const element of elements) {
64+
const text = await element.getText();
65+
if (text === "Cancel") {
66+
await element.click();
67+
break;
68+
}
69+
}
5870
return true;
5971
}
6072
}

packages/databricks-vscode/src/test/e2e/utils/commonUtils.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
ViewControl,
77
ViewSection,
88
InputBox,
9+
OutputView,
10+
TreeItem,
911
} from "wdio-vscode-service";
1012

1113
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -19,6 +21,17 @@ const ViewSectionTypes = [
1921
] as const;
2022
export type ViewSectionType = (typeof ViewSectionTypes)[number];
2123

24+
export async function selectOutputChannel(
25+
outputView: OutputView,
26+
channelName: string
27+
) {
28+
if ((await outputView.getCurrentChannel()) === channelName) {
29+
return;
30+
}
31+
outputView.locatorMap.BottomBarViews.outputChannels = `ul[aria-label="Output actions"] select`;
32+
await outputView.selectChannel(channelName);
33+
}
34+
2235
export async function findViewSection(name: ViewSectionType) {
2336
const workbench = await browser.getWorkbench();
2437

@@ -41,12 +54,14 @@ export async function findViewSection(name: ViewSectionType) {
4154
);
4255
const views =
4356
(await (await control?.openView())?.getContent()?.getSections()) ?? [];
57+
console.log("Views:", views.length);
4458
for (const v of views) {
45-
const title = await v.getTitle();
59+
const title = await v.elem.getText();
60+
console.log("View title:", title);
4661
if (title === null) {
4762
continue;
4863
}
49-
if (title.toUpperCase() === name) {
64+
if (title.toUpperCase().includes(name)) {
5065
return v;
5166
}
5267
}
@@ -335,28 +350,15 @@ export async function waitForNotification(message: string, action?: string) {
335350
);
336351
}
337352

338-
export async function waitForDeployment() {
353+
export async function waitForDeployment(outputView: OutputView) {
339354
console.log("Waiting for deployment to finish");
340-
const workbench = await driver.getWorkbench();
355+
await browser.executeWorkbench(async (vscode) => {
356+
await vscode.commands.executeCommand("workbench.panel.output.focus");
357+
});
358+
await selectOutputChannel(outputView, "Databricks Bundle Logs");
341359
await browser.waitUntil(
342360
async () => {
343361
try {
344-
await browser.executeWorkbench(async (vscode) => {
345-
await vscode.commands.executeCommand(
346-
"workbench.panel.output.focus"
347-
);
348-
});
349-
const outputView = await workbench
350-
.getBottomBar()
351-
.openOutputView();
352-
353-
if (
354-
(await outputView.getCurrentChannel()) !==
355-
"Databricks Bundle Logs"
356-
) {
357-
await outputView.selectChannel("Databricks Bundle Logs");
358-
}
359-
360362
const logs = (await outputView.getText()).join("");
361363
console.log("------------ Bundle Output ------------");
362364
console.log(logs);
@@ -376,3 +378,22 @@ export async function waitForDeployment() {
376378
}
377379
);
378380
}
381+
382+
export async function getActionButton(item: TreeItem, label: string) {
383+
const actions = await item.getActionButtons();
384+
if (actions.length > 0) {
385+
for (const item of actions) {
386+
console.log("Checking action button:", item.getLabel());
387+
console.log(
388+
"Action button element:",
389+
await (await item.elem).getHTML()
390+
);
391+
const itemLabel =
392+
item.getLabel() ?? (await item.elem.getAttribute("aria-label"));
393+
if (itemLabel.indexOf(label) > -1) {
394+
return item;
395+
}
396+
}
397+
}
398+
return undefined;
399+
}

packages/databricks-vscode/src/test/e2e/wdio.conf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const config: Options.Testrunner = {
169169
return [
170170
{
171171
"browserName": "vscode",
172-
"browserVersion": engines.vscode.replace("^", ""),
172+
"browserVersion": engines.vscode.replace(/\^/, ""),
173173
"wdio:vscodeOptions": {
174174
extensionPath: path.resolve(
175175
__dirname,

0 commit comments

Comments
 (0)