Easy File Validation

  April 04, 2008



When you're testing to make sure your application's installer works properly, you usually have to validate that all the files have been successfully loaded onto your target system. If your application installs a complex directory structure with dozens or hundreds of files, this can be an onerous and time consuming task. But what if I told you there was a way to do this with TestComplete? A way, in fact, that would allow you to validate the presence of literally thousands of files in just a few seconds? TestComplete can make this possible  with a simple custom function.

To take advantage of this, you'll need a txt file or an xml file that contains a list of the files you're looking to validate. Most install tools can generate a list of the files they're going to lay down on a system, so your build engineer can most likely provide you with one. Once you have that, you can call one of these helper functions:

validateFileListTxt
validateFileListXml

validateFileListTxt reads through each line of a text file and then calls TestComplete's FileExists method to see if the file is present on the system. If it is, a success message is logged. If it's not, a failure message is logged.

validatefileListXML is similar, except now we're looking through an xml file. Note that you may need to adjust the tag names to reflect the structure of your particular file. (I've included a sample in the downloadable zip file)

If you're unable to get a list of files from your build engineer, you can always create your own, assuming you have a good working install of your product. You could open up notepad and type in the file & path for every file. Or, you could have TestComplete build that file for you.

The generateFileList function reads through a directory and its subdirectories, and generates a txt file that lists their contents. You just specify the directory whose contents you want to list and TestComplete will list of all the files in that directory and save it off as a text file.

These helper functions were written in JScript, but you can easily adapt them to one of the other languages TestComplete supports. Click the link at the bottom right of this column to download the functions. Each of the functions is documented and includes usage examples.


Onward Automation!