'How to check if a file has downloaded successfully?

My page has a link that on clicking will download a file. I just need to check if the file has been downloaded and of the correct extension.



Solution 1:[1]

For checking download with Chrome browser

The set up you can go for is as per the following

https://stackoverflow.com/a/26127745/511069

As suggested here https://stackoverflow.com/a/27031924/511069

you can create a function waitFileExists(fileAbsPath) and performs your expectations after the file is completely downloaded

Solution 2:[2]

var downloadfile = path.join(__dirname,'\\dash-e2e-tests\\resources\\files-cabin\\download-files');

capabilities: {
    browserName: 'chrome',
    'chromeOptions': {
        prefs: {
            download: {
                'prompt_for_download': false,
                'directory_upgrade': true,
                'default_directory': downloadfile
            }
        }
    }

},

Use tabove code under cof.js file and once test case is done verify the file availability under given location.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Shiwantha Lakmal