-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
@jennifer-shehane Any update |
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 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? |
Without a reproducible example we can easily run I cannot say
…Sent from my iPhone
On Dec 18, 2020, at 16:28, norvinino ***@***.***> wrote:
@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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
i before('Login Page', () => {
}) |
@jennifer-shehane Any update |
@bahmutov |
If the file is downloaded and you just don’t know it’s name you could write code inside the plugins file and call it using cy.task. The code could glob the downloads folder to find the downloaded file
…Sent from my iPhone
On Dec 21, 2020, at 10:52, norvinino ***@***.***> wrote:
@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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@bahmutov Please could you help me with an example. I would appreciate. |
We have lots of task examples in https://on.cypress.io/task and lots of
file download and verification examples in
https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/testing-dom__download
to learn from
…On Mon, Dec 21, 2020 at 10:58 AM norvinino ***@***.***> wrote:
@bahmutov <https://github.com/bahmutov> Please could you help me with an
example. I would appreciate.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8677 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQ4BJV4QUKINAT77ECO5XTSV5WA3ANCNFSM4R2KMPQA>
.
--
Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via
https://calendly.com/bahmutov
gleb.bahmutov@gmail.com @bahmutov <https://twitter.com/@bahmutov>
https://glebbahmutov.com/ https://glebbahmutov.com/blog
https://github.com/bahmutov
|
@bahmutov Thank you very much! |
@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
}
})
} |
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. |
@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 |
@bahmutov
|
I am unfamiliar with this NPM module. I suggest you try using globby module to find the file
…Sent from my iPhone
On Jan 4, 2021, at 18:20, norvinino ***@***.***> wrote:
@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 = '/';
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@bahmutov This is the command line I am using: const globby = require ('globby');
(async () => {
const paths = await globby ('archive', {
expandDirectories: {
files: ['* .xlsx'],
}
});
cy.log (paths);
}) (); |
You are accessing the file on disk - you have to write this code in your plugins file and call it using cy.task command
…Sent from my iPhone
On Jan 4, 2021, at 18:30, norvinino ***@***.***> wrote:
@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);
}) ();
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@bahmutov |
@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?!!! |
@bahmutov |
@bahmutov |
@bahmutov |
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 |
I guess what you want is to get the dynamic downloaded file name from a response. I would recommend you to use |
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.
The text was updated successfully, but these errors were encountered: