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

Don't wait for page load when clicking a download link #8677

Closed
norvinino opened this issue Sep 25, 2020 · 29 comments
Closed

Don't wait for page load when clicking a download link #8677

norvinino opened this issue Sep 25, 2020 · 29 comments

Comments

@norvinino
Copy link

norvinino commented Sep 25, 2020

Clicking this download link works fine, but I can't stop cypress from waiting for a nonexistant page to load, which prevents the rest of the test from running.
image

@norvinino
Copy link
Author

Clicking this download link works fine, but I can't stop cypress from waiting for a nonexistant page to load, which prevents the rest of the test from running.
image

@norvinino
Copy link
Author

@jennifer-shehane Any update

@bahmutov
Copy link
Contributor

There are no updates on this issue, but we are lacking a reproducible example. We have multiple file downloads examples in the recipe "File download" https://github.com/cypress-io/cypress-example-recipes#testing-the-dom and would love to see the code that you use to generate the download.

@bahmutov bahmutov added the stage: needs information Not enough info to reproduce the issue label Dec 18, 2020
@norvinino
Copy link
Author

@bahmutov
is investigating and I saw that they gave a response to a similar case. Detail: #8619

@norvinino
Copy link
Author

@bahmutov but I am validating that a file was exported in cypress, but it gives me an error as the file name varies depending on the download as it has the download date and the sequence code. How can I validate without putting the specific name of the file?

@bahmutov
Copy link
Contributor

bahmutov commented Dec 18, 2020 via email

@norvinino
Copy link
Author

@bahmutov

i before('Login Page', () => {
authapp.login()
cy.wait(3000)
cy.get('#panelContentpaneljqxwTree').contains('Accounting').click().wait(1000)
cy.get('#panelContentpaneljqxwTree').contains('Maintenance').click().wait(1000)
cy.get('#panelContentpaneljqxwTree').contains('Roles').click().wait(1000)
cy.url().should("include", "/FIViews/RolePermissionUserView?cid=1").wait(2000)
})

it(' Exporting Role', function () {

   
    cy.get('#ERP_Toolbar').find('.jqx-item').eq(7).click().wait(5000)
    cy.readFile('/Users/Gateway/Downloads/RolePermissionsExport_20201217_083339.xlsx').should('exist')

});

it('Logout Page', function () {
    authapp.logout()
})

})

@norvinino
Copy link
Author

image

@norvinino
Copy link
Author

@jennifer-shehane Any update

@norvinino
Copy link
Author

@bahmutov
For privacy and security reasons I cannot send a video with the reroduction of the request.
Basically in the application I am testing a button to export a file, it turns out that I want to validate that the file is expert or downloaded. I am using the following statement cy.readFile ('/ Users / Gateway / Downloads / RolePermissionsExport_20201217_083339.xlsx'). Should ('exist')
the issue is that the file changes its name when downloaded again and cannot be validated. and each time the export is executed it has a different name. How to do it in that case.

@bahmutov
Copy link
Contributor

bahmutov commented Dec 21, 2020 via email

@norvinino
Copy link
Author

@bahmutov Please could you help me with an example. I would appreciate.

@bahmutov
Copy link
Contributor

bahmutov commented Dec 21, 2020 via email

@norvinino
Copy link
Author

@bahmutov Thank you very much!
I will verify.

@norvinino
Copy link
Author

norvinino commented Jan 4, 2021

@bahmutov As I'm new to Cypress, I've to write a test case to check whether the file is downloaded or not, I've been through multiple posts related to the similar test case, but all of them having the test case to read a file which has a static name, in my case I've to read a file which is downloaded after clicking the download button and every time the file is downloaded it will have a dynamic name, though the filename has some patterns (ex. filename starts with a fixed set of characters).

I wanted to achieve something like this in cypress,

cy.readFile('C:\Users\UserName\Downloads${Regular expression to match the filename pattern}

Below is the snippet from cy.task() documentation

// in plugins/index.js
const fs = require('fs')

module.exports = (on, config) => {
  on('task', {
    readFileMaybe (filename) {
      if (fs.existsSync(filename)) {
        return fs.readFileSync(filename, 'utf8')
      }

      return null
    }
  })
}

@bahmutov
Copy link
Contributor

bahmutov commented Jan 4, 2021

You can use something like https://github.com/sindresorhus/globby to find a file in the downloads folder if you don't know the exact filename.

@norvinino
Copy link
Author

@bahmutov Can you help me with a clearer example of globby because it doesn't work for me. The directory is the next /Users/Gateway/Downloads/ one and the file to check if it exists is a .xlsx

Thanks in advance

@norvinino
Copy link
Author

norvinino commented Jan 4, 2021

@bahmutov
This is the error that appears and I cannot move forward:

Cannot read property 'dirname' of undefined
node_modules/glob-parent/index.js:4:38
  2 | 
  3 | var isGlob = require('is-glob');
> 4 | var pathPosixDirname = require('path').posix.dirname;
    |                                      ^
  5 | var isWin32 = require('os').platform() === 'win32';
  6 | 
  7 | var slash = '/';

@bahmutov
Copy link
Contributor

bahmutov commented Jan 4, 2021 via email

@norvinino
Copy link
Author

norvinino commented Jan 4, 2021

@bahmutov
I am using the globby module and that is the error that I get.

This is the command line I am using:

   const globby = require ('globby');
           (async () => {
              const paths = await globby ('archive', {
             expandDirectories: {
                files: ['* .xlsx'],
             }
               });
            cy.log (paths);
            }) ();

@bahmutov
Copy link
Contributor

bahmutov commented Jan 4, 2021 via email

@norvinino
Copy link
Author

@bahmutov
It doesn't work for me yet. Will you have an example please. I really don't know what else to do.

@bahmutov
Copy link
Contributor

bahmutov commented Jan 5, 2021

@norvinino I am sorry it is not working for you, but this is basic Node code that you should be able to run following the globby examples.

Also - did you just post a link to a site that simply steals my blog posts from https://glebbahmutov.com/blog/ and reposts them? And it has a nerve to block my browser because it blocks ads?!!!

@norvinino
Copy link
Author

@bahmutov
That was not my intention, at no time do I want to cause him any harm. Is that searching the internet I got that. Rather, what I want is for you to help me. Excuse me if I did something wrong.

@norvinino
Copy link
Author

@bahmutov
Mr. Gleb Bahmutov, really excuse me, it was not my intention to do anything wrong.

@norvinino
Copy link
Author

@bahmutov
Mr. Gleb Bahmutov, please help me to solve this case. I'm sorry.

@bahmutov
Copy link
Contributor

bahmutov commented Jan 5, 2021

See how to do this in cypress-io/cypress-example-recipes#616 and please do not use sites that just steal other people's posts. You can see all the important links https://on.cypress.io/blogs-media

@bahmutov bahmutov closed this as completed Jan 5, 2021
@norvinino
Copy link
Author

@bahmutov
Thank you very much for the information and the recommendation. It will not happen again. I will review what you send me.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Jan 7, 2021
@YiniXu9506
Copy link

YiniXu9506 commented Jan 27, 2022

I guess what you want is to get the dynamic downloaded file name from a response. I would recommend you to use cy.intercept to get the filename from your download/ response.

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

No branches or pull requests

4 participants