How to validate a successful file download test senario from selenium



  • I need to automate the following test senario where

    when I click on a button, a file will be downloaded

    There will be no message box and no text message. How should I implement this scenario using selenium script?



  • You can check the filesystem for the downloaded file:

    private boolean isFileDownloaded(String downloadPath, String fileName){
        boolean flag = false;
        File dir = new File(downloadPath);
        File[] dirContent = dir.listFiles();
    
        assert dirContent != null;
        for(File file : dirContent){
            if (file.getName().equals(fileName)) { return flag = true; }
        }
        return flag;
    }
    

    NOTE: This is a Java implementation, you can use the same idea in C#.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2