Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Does upload.() return a promise? #97

Closed
kyledavelaar opened this issue Aug 5, 2019 · 10 comments
Closed

[Feature] Does upload.() return a promise? #97

kyledavelaar opened this issue Aug 5, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@kyledavelaar
Copy link

kyledavelaar commented Aug 5, 2019

Desired behavior:

Great library! Thanks for making this. Not sure if this is a bug or could be a new feature. I'd like upload() to wait until the file has been uploaded and then do something like click a button on the page. In the code below it seems that upload() is not waiting for the file to finish uploading before going into the second .then() block.

Current behavior:

cy.fixture('./3row.csv').then(fileContent => { cy.get('input[type="file"]').upload({ fileContent, fileName: './3row.csv', mimeType: 'text/csv' }).then(content => { cy.get('[data-cy="map-headers-container"]').contains('NEXT').click({force: true}); }) }); })

Versions

cypress 3.4

@kyledavelaar kyledavelaar added the enhancement New feature or request label Aug 5, 2019
@abramenal
Copy link
Owner

abramenal commented Aug 5, 2019

Hey @kyledavelaar
Thanks for submitting the issue!

We discussed that stuff in #91, here's the answer:

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 to you?

@kyledavelaar
Copy link
Author

Hi @abramenal
Thanks for the response. Unfortunately I am not needing to wait for an xhr request but for the file to be uploaded. In my app after I upload the file, I show data on the screen about the file, row mappings (it's a csv file), etc. and I find that when I immediately have cypress look for them after the upload(), they are not there yet. Currently I am doing a cypress.wait(500) but I'd like to avoid that if possible via a promise or something like cypress does with xhr aliases.

@abramenal
Copy link
Owner

@kyledavelaar
Oh I see what you mean. Yes, then likely I need to go through the Promise chain in order to resolve it properly – will likely pick that up this week.

@kyledavelaar
Copy link
Author

kyledavelaar commented Aug 7, 2019 via email

@abramenal
Copy link
Owner

@kyledavelaar
Can you tell what version of cypress-file-upload you're using?
Also, what is the size of that CSV you're uploading?
And finally, what is this data-cy="map-headers-container" component?

I feel a bit of misconception here. Ideally you don't need to control the async flow this way – Cypress does that for you for most cases. See
https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Noisy-Promise-demonstration-Not-valid-code

So can you try out this:

cy.fixture('./3row.csv').then(fileContent => {
  cy.
      get('input[type="file"]')
      .upload({ fileContent, fileName: './3row.csv', mimeType: 'text/csv' });
});

cy
  .get('[data-cy="map-headers-container"]')
  .contains('NEXT')
  .click({ force: true });

After that, the problem I see here is that your data-cy="map-headers-container" component might not receive/render data you need immediately when the plugin inserts it (or at least does it in async way). So same thing here, ideally Cypress will resolve async stuff automatically.

If we omit async part, cy.contains command also has timeout value as time for your data to appear (before the whole command gets rejected. See https://docs.cypress.io/api/commands/contains.html#Arguments

Waiting for your reply.

@kyledavelaar
Copy link
Author

Sorry was out on holiday and couldn't investigate more. I see what you mean about the way Cypress handles async. To answer your questions I'm using the latest version of cypress-file-upload, the size of the csv is 88 bytes, and the data-attribute is for the container that holds the NEXT button.

@abramenal
Copy link
Owner

@kyledavelaar is the issue still relevant to you?
If yes, you could take a look on #104 bug description, there is a nice way to do the thing which is likely to be same as yours.
If that does not help still, please reopen this one with details.

@kyledavelaar
Copy link
Author

kyledavelaar commented Sep 21, 2019 via email

@BavithraDuraisamy
Copy link

@kyledavelaar
Can you tell what version of cypress-file-upload you're using?
Also, what is the size of that CSV you're uploading?
And finally, what is this data-cy="map-headers-container" component?

I feel a bit of misconception here. Ideally you don't need to control the async flow this way – Cypress does that for you for most cases. See
https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Noisy-Promise-demonstration-Not-valid-code

So can you try out this:

cy.fixture('./3row.csv').then(fileContent => {
  cy.
      get('input[type="file"]')
      .upload({ fileContent, fileName: './3row.csv', mimeType: 'text/csv' });
});

cy
  .get('[data-cy="map-headers-container"]')
  .contains('NEXT')
  .click({ force: true });

After that, the problem I see here is that your data-cy="map-headers-container" component might not receive/render data you need immediately when the plugin inserts it (or at least does it in async way). So same thing here, ideally Cypress will resolve async stuff automatically.

If we omit async part, cy.contains command also has timeout value as time for your data to appear (before the whole command gets rejected. See https://docs.cypress.io/api/commands/contains.html#Arguments

Waiting for your reply.

i'm getting this error when trying to upload csv file
passed subject element is not valid.

@abramenal
Copy link
Owner

Hi @BavithraDuraisamy
Let's create a new issue where you describe your setup with code snippets so I can help you quickly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants