// gives count of downloads in download folder.
this.getCountOfDownloads = function (fileName,elementToClick) {

    //provides a way to look for filenames matching a certain pattern (in the worst case, you can wait for the *.* - basically, any file to appear)
    var glob = require("glob");
    var filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx");


    browser.driver.wait(function () {
        elementToClick.click();//to download

        if (typeof filesArray !== 'undefined' && filesArray.length > 0) {
            // this check is necessary because `glob.sync` can return
            // an empty list, which will be considered as a valid output
            // making the wait to end.

            return filesArray;
    }, 4444).then(function (filesArray) {

        // now we have the filename and can do whatever we want
    browser.sleep(5555); console.log("sizee",filesArray.length);

elemtclick downloads file.

I can see in intelj when I click sync button.

At first it is empty. Then I run this and it shows size as 0 at both console output. Then in next run, it becomes 1 because the file downloaded before. filesarray> 0 is not becoming true.

I put browser.sleep() after element.click() but it still does not wait for file or does not sync with it.

What I want to do is:

  • I get the counts of downloading before the operation
  • I get the counts after downloaded
  • I expect count = currentcount - 1

But it cannot see the file, why?

I think I have to refresh the session but maybe there is an another way.


Your click (and download) is after the glob.sync().

After the download, you need to do another glob.sync() to read the new state of the directory.

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.