Playwrightでファイル選択をする

Playwright は FileChooser オブジェクトを利用すると、ファイル選択をエミュレートできる。

https://playwright.dev/docs/api/class-filechooser

const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByText("Upload file").click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, "myfile.pdf"));