abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
496 stars 89 forks source link

[Question] How to add custom file #363

Closed BarryThrill closed 2 years ago

BarryThrill commented 2 years ago

Hello people!

I'm currently working on doing a drag and drop file where I basically have a file format called BMPROJ which contains a JSON. However the website works that it needs to drag and drop the file as a BMPROJ file to be able to accept it (A raw json would not work) and inside the BMPROJ it is just a simple json file.

The reason I am writing here is that I have a code that is following:

          cy.get('.mod-view-3d').attachFile({
            filePath: 'C:/Users/Barry-PC/Desktop/BOM/1BC475E2-7578-471A-AD23-K51H1528FH1.BMPROJ',
            encoding: 'utf-8'
          }, {
            force: true,
            subjectType: 'drag-n-drop'
          });

And what I want to do is to drag and drop the file 1BC475E2-7578-471A-AD23-K51H1528FH1.BMPROJ however the error I do get is:

A fixture file could not be found at any of the following paths:

> cypress\fixtures\C:\Users\Barry-PC\Desktop\BOM\1BC475E2-7578-471A-AD23-16ED72F30C1E.BMPROJ
> cypress\fixtures\C:\Users\Barry-PC\Desktop\BOM\1BC475E2-7578-471A-AD23-16ED72F30C1E.BMPROJ{{extension}}

Cypress looked for these file extensions at the provided path:

> .json, .js, .coffee, .html, .txt, .csv, .png, .jpg, .jpeg, .gif, .tif, .tiff, .zip

Provide a path to an existing fixture file.

My question is - How am I able to drag and drop the file?

Regards,

Barry

abramenal commented 2 years ago

Hi @BarryThrill, Thanks for submitting the issue!

Currently there's no way to give the tool absolute file path. For doing what you want, you can use raw file contents: https://github.com/abramenal/cypress-file-upload/tree/v5.0.8#working-with-raw-file-contents

Let me know if that works out. Also feel free to reopen in case you have something concerning this.