|
1 | | -import { test, expect } from "@playwright/test"; |
| 1 | +import { test, expect, Page } from "@playwright/test"; |
2 | 2 | import { FIXTURES, getFixturePath } from "./utils/fixtures"; |
3 | 3 |
|
| 4 | +/** |
| 5 | + * Upload a file using the file chooser dialog. |
| 6 | + * react-dropzone's hidden input doesn't respond to Playwright's setInputFiles, |
| 7 | + * so we click the "Upload file" button and use the file chooser event instead. |
| 8 | + */ |
| 9 | +async function uploadFile(page: Page, filePath: string) { |
| 10 | + const uploadButton = page.getByRole("button", { name: "Upload file" }); |
| 11 | + await expect(uploadButton).toBeVisible({ timeout: 5000 }); |
| 12 | + |
| 13 | + const [fileChooser] = await Promise.all([page.waitForEvent("filechooser"), uploadButton.click()]); |
| 14 | + await fileChooser.setFiles(filePath); |
| 15 | +} |
| 16 | + |
4 | 17 | test.describe("Trace file loading", () => { |
5 | 18 | test("should load io-trace-output.log without crashing", async ({ page }) => { |
6 | 19 | await page.goto("/", { waitUntil: "domcontentloaded" }); |
7 | 20 | await page.evaluate(() => window.localStorage.clear()); |
8 | 21 |
|
9 | | - const fileInput = page.locator('input[type="file"]'); |
10 | 22 | const tracePath = getFixturePath(FIXTURES.IO_TRACE_OUTPUT); |
11 | | - |
12 | | - await fileInput.setInputFiles(tracePath); |
| 23 | + await uploadFile(page, tracePath); |
13 | 24 |
|
14 | 25 | // Wait for load button to be ready instead of fixed timeout |
15 | 26 | const loadButton = page.getByTestId("load-button"); |
@@ -44,14 +55,13 @@ test.describe("Trace file loading", () => { |
44 | 55 | await page.goto("/", { waitUntil: "domcontentloaded" }); |
45 | 56 | await page.evaluate(() => window.localStorage.clear()); |
46 | 57 |
|
47 | | - const fileInput = page.locator('input[type="file"]'); |
48 | 58 | const tracePath = getFixturePath(FIXTURES.IO_TRACE_OUTPUT); |
49 | | - |
50 | | - await fileInput.setInputFiles(tracePath); |
| 59 | + await uploadFile(page, tracePath); |
51 | 60 |
|
52 | 61 | // Wait for load button to be ready |
53 | 62 | const loadButton = page.getByTestId("load-button"); |
54 | 63 | await expect(loadButton).toBeVisible({ timeout: 5000 }); |
| 64 | + await expect(loadButton).toBeEnabled({ timeout: 5000 }); |
55 | 65 | await loadButton.click(); |
56 | 66 |
|
57 | 67 | // Wait for program status to appear |
|
0 commit comments