0

I am trying to upload a file without an input element with cypress-file-upload library, using .attachFile(), and I haven't be able so far. I don't get any error it just doesn't upload the file. I have tried it in other part of my app with input element and it is working fine. Is there any other way of doing it? Or am I doing something wrong?

cy.get('.bp3-card .post-header-image').contains('Reply').click()  
        cy.get('.editor').find('[title="Attach File"]').click()
        cy.contains('Upload Attachment').should('contain', 'Upload Attachment') 
        cy.get('.bp3-dialog-body > button').click()
        
        .selectFile(
          ['cypress/fixtures/sipder.png'],{action: 'drag-drop', encoding: 'utf-8'}
        )
        cy.wait(3000)
        const file_path = "sipder.png"
        cy.get('.bp3-dialog > .bp3-dialog-body').find('button').attachFile(file_path);
        cy.wait(3000)

Here is HTML. Basically, cypress allows type but here is a button, I'm trying to upload its upload file but it does not display the upload file's functionality in UI. You can see in the image below

Image

user16217248
  • 3,119
  • 19
  • 19
  • 37
  • if i am right then your issue is you dont want to show input & need to display button to upload right? – Parth M. Dave May 15 '23 at 07:36
  • No, I'm talking about How to upload an image using a span button element, without using the input type="file" tag. using like
    class= " bp3-button"

    Button Click

    – Muhammad Abu Zar May 16 '23 at 13:13
  • See without input="file" not possible to upload but yes we can do like file type is hidden & using span we can handle. – Parth M. Dave May 17 '23 at 03:42

1 Answers1

0

Html

<input type="file" name="file" id="importFile" (change)="onFileChange($event.target)" style="visiblity:hidden">
<span for="importFile">Click to Upload!</span>

Typescript

onFileChange(pFileList: any ) { // pFileList is file object which is selected for upload }

I think from above snap of code you can understand that 'input' control is hidden & on click of span.

Parth M. Dave
  • 853
  • 1
  • 5
  • 16