Make fileChooser platform independent. (#41500)

* Make fileChooser platform independent.

Fixes #41474

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

* Added node: prefix to imports.

Signed-off-by: Stan Silvert <ssilvert@redhat.com>

---------

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
This commit is contained in:
Stan Silvert
2025-07-30 13:21:05 -04:00
committed by GitHub
parent 1ac1f37508
commit e82f76aee5
2 changed files with 10 additions and 18 deletions
+2 -14
View File
@@ -1,8 +1,8 @@
import { expect, test } from "@playwright/test";
import path from "path";
import { v4 as uuid } from "uuid";
import adminClient from "../utils/AdminClient";
import { assertRequiredFieldError } from "../utils/form";
import { chooseFile } from "../utils/file-chooser";
import { login } from "../utils/login";
import { assertNotificationMessage } from "../utils/masthead";
import { assertModalTitle, confirmModal } from "../utils/modal";
@@ -132,19 +132,7 @@ test.describe("Clients test", () => {
test("Import client", async ({ page }) => {
await page.getByTestId("importClient").click();
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByText("Browse...").click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(
new URL(
path.join(
path.dirname(import.meta.url),
"../utils/files/import-identical-client.json",
),
).pathname,
);
await chooseFile(page, "../utils/files/import-identical-client.json");
await save(page);
await assertNotificationMessage(
page,
+8 -4
View File
@@ -1,11 +1,15 @@
import { Page } from "@playwright/test";
import path from "path";
import path from "node:path";
import { fileURLToPath } from "node:url";
export async function chooseFile(page: Page, file: string) {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByText("Browse...").click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(
new URL(path.join(path.dirname(import.meta.url), file)).pathname,
);
const fileName = fileURLToPath(import.meta.url);
const dirName = path.dirname(fileName);
const pathName = path.resolve(dirName, file);
await fileChooser.setFiles(pathName);
}