This is the path

 capabilities: {
        'browserName': 'chrome',
        'chromeOptions': {

            prefs: {
                download: {
                    'prompt_for_download': false,
                    'directory_upgrade': true,
                    'default_directory':  'src/test/javascript/e2e/downloads'

I download the file with this,


It downloads the file, but I am not able to check if it was downloaded. It has only count in name, so I can check if it contains count.

After all is done I will delete files, so only those files will stay after I download.

I did lots of things but could not manage.

  • You could try opening the file as outlined in this SO answer.
    – kirbycope
    Dec 5 '16 at 18:01
  • You may also apply (with the help of browser.wait()) glob to the downloads directory: stackoverflow.com/questions/41082777/….
    – alecxe
    Jun 7 '17 at 3:11
  • How can i create multiple directories inside /src/test/javascript/e2e location? the thing is I want to download two different files in two different directories let say download1/ and download2. How can i achieve this? capabilities: { 'browserName': 'chrome', 'chromeOptions': { prefs: { download: { 'prompt_for_download': false, 'directory_upgrade': true, 'default_directory': 'src/test/javascript/e2e/downloads' } } } }
    – user47928
    Dec 31 '20 at 6:55
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Dec 31 '20 at 8:56

First delete any already downloaded files in the download location:

 deleteAlreadyDownloadedFiles: function(){
      var filename = global.downloadsPath + '/fileName.extension';
      var fs = require('fs');
      if (fs.existsSync(filename))
        // delete if there is any existing file with same name


And perform the download action and then verify the file is downloaded or not:

 verifyFileDownload: function() {
  var filename = global.downloadsPath + '/fileName.extension';
    browser.driver.wait(function() {
      return fs.existsSync(filename);
    }, 30000).then(function() {
      console.log("Getting the ERROR while downloading file as file is not downloaded.");



This is how I did, in protractor+typescript using Jasmine. If anybody knows better implementation please do share.

First, do:

npm install download-file --save

Page Object:

const downloadsFolder = require('downloads-folder');
const fs = require('fs');

export class TestPage{

async verifyFileInDownloadsFolder(fileName: string) {
    await console.log('Getting users download path ' + downloadsFolder());
    const filePath = (downloadsFolder() + '\\' + fileName). replace(/\\/g, '/');
    await console.log('Getting the path ' + filePath);
    await browser.wait(async() => fs.existsSync(filePath), this.DEFAULT_WAIT_TIME_SECONDS * 1000, 'File never appeared!');
    await expect(fs.existsSync(filePath)).toBe(true,
      'Failed to download file: ' +  fileName + ' in user directory' + filePath);
    await console.log('File download was successful');


Import {TestPage} from './projectpath.po'

describe('testsuite desc', ()=> { 
    let test: TestPage;
    beforeEach( async()=> {
        test = new TestPage();

    describe('test case name', ()=> {
        it('TC desc', async()=> {
            await test.verifyFileInDownloadsFolder(abc.docx);

Not the answer you're looking for? Browse other questions tagged or ask your own question.