[SOLVED] ENOENT: no such file or directory, when attempting to upload a file with playwright


I cant seem to figure out why the file Im trying to use as an upload wont work, I’ve created this upload function

async uploadFile(file: string) {
    await this.fileUploadIcon.click();
    await this.page.setInputFiles('.file-upload-input', file);

which is being used in the test:

test.only('Upload a document', async () => {
    await uploadActions.uploadFile(firstDoc);

the first doc is being initialized with this path:

const firstDoc = '../Assets/Automated_Doc_2.pdf';

but the test fails and the path besides the ENOENT: no such file or directory error looks correct.

What am I doing wrong?


You forgot to await the expect -> await expect....

Also I’d recommend to use path.join(__dirname, '../Assets/Autoamted_Doc_2.pdf) which is a better way of dealing with paths, since otherwise its CWD (current working directory) based.

To import path, you have to: import path from 'path';

Using both should make it work.

Answered By – Max Schmitt

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *