Cypress-file-upload: Waiting for the upload to complete

Created on 19 Jul 2019  Â·  3Comments  Â·  Source: abramenal/cypress-file-upload

Current behavior:

I have created a custom command that takes in the file name, mime type, encoding, and an attribute value to grab the specific component that will be handling the upload. Everything works, but I have found that Cypress will move on to the next test, even though the upload has not completed. Which can fail future tests waiting for the data from the upload.

Desired behavior:

I want to be able to track the output so I can halt Cypress from continuing on until upload is complete

Steps to reproduce: (app code and test code)

There really aren't reproducible steps, but I will include my custom command so you can see what I am currently doing.

Cypress.Commands.add(
  'upload_via_dropzone',
  (attrVal, fileName, mimeType, encoding, subjectType = 'drag-n-drop') => {
    return cy.fixture(fileName, encoding).then(fileContent => {
      cy.get(`[data-test="${attrVal}"]`).upload(
        { fileContent, fileName, mimeType, encoding },
        { subjectType, force: true },
      );
    });
  },
);

Versions

Cypres v3.3.1, OS: Mojave, Chrome

bug

Most helpful comment

I see what you mean. The API call I make after I upload is the process that needs to be waited on, not the upload itself. That makes more sense. I don't know why I was thinking it was the other way around.

I will show myself out lol

All 3 comments

Hi @zach446
Thanks for submitting the issue!

I think that is definitely a good case. Hopefully investigate that during the weekend.

Well, after thinking a while here's the suggestion.

I think the upload process you mention is more about waiting network request to complete – correct me if I'm wrong.
If that is correct, the only way to do it properly is:
https://docs.cypress.io/api/commands/wait.html#Wait-for-a-specific-XHR-to-respond

Does this help? Or you have something else on your mind?

I see what you mean. The API call I make after I upload is the process that needs to be waited on, not the upload itself. That makes more sense. I don't know why I was thinking it was the other way around.

I will show myself out lol

Was this page helpful?
0 / 5 - 0 ratings