-
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
Add support for changing path to the downloads folder in cypress configuration #4675
Comments
Could you be more specific about what 'it' is here? What is downloading to this path? Are you talking about downloading Cypress? |
I'm running test in cypress which downloads the file. I think a nice feature would be that users could specify where the file should be downloaded. For example |
I think joszo may mean Setting the default download folder to a specific path. There's quite a bit of past-history when doing this using chrome headless and selenium, so there might be some additional research to do. |
This is exactly what I meant :) In Protractor there was something like that: var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
................
'chromeOptions': {
prefs: {
download: {
'prompt_for_download': false,
'default_directory': downloadsPath
}
}
} And then we could specify the default folder to the cypress folder, so we could easier verify files, delete them or whatever we want to do with them. So far I created some workaround for my purpose: module.exports = (on, config) => {
on('task', {
deleteFile(fileName) {
const fs = require('fs');
const userName = require('os').userInfo().username;
const downloadPath = `/Users/${userName}/Downloads/`;
const absolutePath = downloadPath + fileName;
const fileStats = fs.statSync(absolutePath);
const fileSize = fileStats.size;
if (fs.existsSync(absolutePath) && fileSize > 0) {
try {
fs.unlinkSync(absolutePath);
console.log('File deleted');
return null;
} catch (err) {
console.log(err);
}
}
console.log('File is not exists');
return null;
}
});
}; And usage looks like that: cy.task('deleteFile', `${fileName}.pdf`) I know that is not beautiful... but I'm not sure how it would behave on CI etc... 😢 |
Thanks for clarifying! This feature is duplicate of a requirement of this issue: #949 You may find some better workarounds in that thread too. |
This issue is not a duplicate, the referenced ticket above focusses on the download dialogue, and only mentions changing the download location. Still having issue in changing the default location |
@natejcho this is exactly what I had in mind :) |
I am also facing the same issue as specified by @joszo |
I replied in this thread my working solution. |
@joszo #4675 (comment) |
I will try tomorrow to run that solution in the CI, and I will inform you @CuriousSoul230 |
This runs fine in our pipeline. Our stack uses Docker and gitlab. we export the downloads as an artifact |
@natejcho In your case do you set the path were the file is downloaded. I need to read the file and assert on some values before deleting them. |
I think the problem will also occur if you will try to run tests in headless mode locally In free time I will try to figure out how to solve it, the solution which comes to mind is like @natejcho mentioned use docker (probably they use it with XVFB, so the tests are run in the CI in GUI mode). Maybe I'm wrong... In the meantime, there is a nice article about using cypress with docker: https://www.cypress.io/blog/2019/05/02/run-cypress-with-a-single-docker-command/ |
#4675 (comment) |
how did you avoid that pop up - #5651 in this issue we have example of pop up. |
@joszo |
in my solution above, the download will save relative to the project root directory so |
in the solution I posted #949 (comment) you intercept the download. Attach the contents of the download to an a tag, read the raw html for the byte string (or whatever format you choose) and then write that to a file in your project directory. |
I faced this today and found the formal docs extremely helpful: |
@ris314, I changed the download folder as u suggested in the previous comment, that code works fine with chrome browser, but I am getting an error while I am running test cases in electron browser
|
Changing the download directory as suggested by the docs plugin example(https://docs.cypress.io/api/plugins/browser-launch-api.html#Change-download-directory) works for me when running with chrome. However, I'm seeing 'TypeError: Cannot set property 'download' of |
Yeah, I think the options have to be different for Electron (sigh). I'll update the docs example. cypress-io/cypress-documentation#2971 I'm thinking this is not going to be configurable in Electron as is so you'll want to run |
File download is now supported in Cypress 6.3.0. You can now test file downloads in Cypress without the download prompt displaying. Any files downloaded while testing file downloads will be stored in the This means that if you had any code written to prevent the download prompt or to configure the download location (like in a Our file download recipe has been updated, so you can see some ways to test different types of files after they've been downloaded there. If you're encountering any bugs while testing file downloads, please open a new issue. |
@jennifer-shehane I want to download the pdf in "Cypress.config('downloadsFolder')" folder. I also used firefox browser preferences also to avoid pop-up and download directly inside my project. But even after multiple trials, I could not. Everytime, i can download only inside default download folder or on Desktop location based on values (0,1) of ['browser.download.folderList'] . Below is the before:browser:launch options that I used in plugins/index.js
Is it possible to download the pdf inside cypress/downloads by using the firefox browser? Thanks in advance |
@shreeti91 IF this is a question on using Cypress, you may want to try asking our community in our GitHub Discussions. As an open source project with a small maintainer team we have to focus our time on bugs and features in the product, which Issues are reserved for. |
Hello,
could you add to the configuration something like:
downloadFolder: cypress/download
Normally it's downloaded to the /Users/username/Downloads/fileName.example but I want to make it more elastic for other people which after running the tests, doesn't have to change path to the downloads.
The text was updated successfully, but these errors were encountered: