Search code examples
typescriptfile-uploadfilepathplaywright

Getting the below error in Playwright when trying to upload a file : Error: ENOENT: no such file or directory


enter image description hereI just started using playwright(using typescript), so I am very new to it. I am having a test script where I need to upload a single file. The element type is non-input HTML so I am choosing Filechooser function for the upload. I have placed the pdf file which needs to be uploaded under the attachments subfolder section. Attaching the image here as well and attaching the code snippet too. As per the screenshot, I am making changes to the WaterTDLApp.Spec.ts which is under tests folder. Tests and attachments folders are under src folder.

Full Error : Error: ENOENT: no such file or directory, stat 'C:\attachments\TDL\relevantfile-sample.pdf'

const filepath = '../../attachments/TDL/relevantfile-sample.pdf';
  
    const [fileChooser] = await Promise.all([
      // It is important to call waitForEvent before click to set up waiting.
      page.waitForEvent('filechooser'),
      // Opens the file chooser.
      page.locator("(//*[@class='ant-upload-drag-container'])[1]").click(),
    ]);

    await  fileChooser.setFiles(filepath)

Could anyone please help me here. Let me know if any other details are needed.enter image description here


Solution

  • So you are running the tests from C:\OneStop 2.0 Automation\E2E, then you have to change the file path to src/attachments/TDL/relevantfile-sample.pdf. This should work.