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.


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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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