Trying to figure out how to upload a file in a TypeScript test using Playwright.
const fileWithPath = './abc.jpg';
const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.getByRole('button', { name: 'Add a Photo' }).click(),
]);
await fileChooser.setFiles([fileWithPath]);
Encountering an error when attempting this:
Error: ENOENT: no such file or directory, stat './abc.jpg'
If I switch the file path to an absolute one, it works:
const fileWithPath = '/Users/private/d/ionic/tests/playwright/optional/abc.jpg';
However, as I develop on macOS but run tests on linux, I would prefer to have the image file (abc.jpg) stored in the same folder as the test and use a relative path that works across operating systems. Any suggestions on how to achieve this?