Forum Discussion

mgroen2's avatar
mgroen2
Super Contributor
8 years ago

How to validate if file is created (on disk)

In my tests, I need to validate if a file is created, physically, on disk (I know the path to where it should be created). What would be the best approach to validate if file is actually existing (created) as part of an automated test?

 

I know opening Windows file explorer, navigating to the folder and create a snapshot would provide some level of proof but I think this is cumbersome, and I think maybe better approaches are possible.

 

Any ideas, tips, are appreciated.

 

 

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You could use the aqFileSystem object. There is a simple "Exists" method on that object that will check to see if a path to a file is valid.  So, just quick and dirty JavaScript:

    function testFileExists(filePath, fileName) {
        return aqFileSystem.Exists(filePath + fileName);
    
    }
    
    function Test1(){
        var result;
        result = testFileExists('C:\\temp\\', 'myfile.txt');
        result ? Log.Message('It is here') : Log.Warning('Nope');
    }
    • bbi's avatar
      bbi
      Contributor

      In addition you can check if folder exists with this function:

       

      function folderExists(Folder) {
          var result = false;
          try {
            result = aqFileSystem.GetFolderInfo(Folder).Exists;
          }
          catch(e) {
          }
          return result;
        };

       The Folder parameter may or may not include the trailing backslah, no matter.