test: add waitForElement util

This commit is contained in:
tomasz-io 2024-12-06 17:22:24 -08:00
parent 66e627b5be
commit af5d5fadb0
2 changed files with 32 additions and 6 deletions

View file

@ -0,0 +1,27 @@
import { WebElement } from "vscode-extension-tester";
export class TestUtils {
public static async waitForElement(
locatorFn: () => Promise<WebElement>,
timeout: number = 1500,
interval: number = 500,
): Promise<any> {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
try {
const element = await locatorFn();
if (element) {
return element;
}
} catch (e) {
if (Date.now() - startTime >= timeout) {
throw new Error(`Element not found after ${timeout}ms timeout`);
}
}
await new Promise((resolve) => setTimeout(resolve, interval));
}
throw new Error(`Element not found after ${timeout}ms timeout`);
}
}

View file

@ -2,13 +2,13 @@ import {
EditorView,
WebView,
WebDriver,
Key,
VSBrowser,
} from "vscode-extension-tester";
import { expect } from "chai";
import { GUIActions } from "../actions/GUI.actions";
import { GUISelectors } from "../selectors/GUI.selectors";
import * as path from "path";
import { TestUtils } from "../TestUtils";
describe("GUI Test", () => {
let view: WebView;
@ -52,10 +52,9 @@ describe("GUI Test", () => {
await tiptap.sendKeys("How are you?");
(await GUISelectors.getSubmitInputButton(view)).click();
await new Promise((res) => {
setTimeout(res, 1000);
});
await GUISelectors.getThreadMessageByText(view, "I'm fine");
await TestUtils.waitForElement(
() => GUISelectors.getThreadMessageByText(view, "I'm fine"),
5000,
);
}).timeout(600000000);
});