1

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?

I am using this:

test code

and this is the code in my app

app code

Any idea? Thanks a lot, any tip is welcome :D

Versions: "cypress-file-upload": "5.0.7" "cypress": "7.7.0", Windows Chrome

Fody
  • 23,754
  • 3
  • 20
  • 37
Sergio
  • 21
  • 3
  • Please [edit] your post to add code and data as text ([using code formatting](https://stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. See [mcve] on what code is required. – Adriaan Jul 21 '22 at 12:05

2 Answers2

0

I was recently looking at the source of cypress-file-upload for someone else's problem, and I don't think it can be done without an input element.

There are two modes

  • "input" which requires you to select the input directly before .attachfile()
  • "drag-n-drop" for which you select a parent of it (the library searches for the input within the parent element)

In your button HTML, how would you attach the file prior to uploading? Does it work manually - if so, you should see a reference to the attached file when inspecting the element.

Fody
  • 23,754
  • 3
  • 20
  • 37
  • Yeah, I found exactly the same :(. When I click it, a windows file selector is opened where I select the file. Afterward, there is a space in the chatbox where the file appears – Sergio Jan 17 '22 at 11:31
0

I am a total beginner, but maybe it will help. I tried with input element, but got the same situation as you - no errors, but file wasn't uploated.

I picked up the class of the input and it worked :) My code:

    cy.get('.class_icannotshare')
        .attachFile('avatar.jpg')

In your case I'd try:

    cy.get('.u-icon c-icon --right icon-attach')