The Corruption Extension
One of my favorite negative tests is to take a file that my AUT should be able to open, corrupt it, and then try and open it. Sometimes I find that my developer has handled this scenario elegantly; sometimes I find a system crash. The process of corrupting the files may be a pain though; you may need to write custom script, or use a special tool that might be out of your company's budget. So I whipped up this script extension that can be used during test design time.
Just install this extension, click the skull & crossbones icon, and select the file you want to corrupt. TestComplete will make a copy of that file in the root of your TC project, and add the file to the Stores node of your project as well. You can then use that file in your testing.
To try it out,
- Download the extension
- Install the extension by copying it to your Script Extensions folder (typically C:Program FilesAutomated QATestComplete 6BinExtensionsScriptExtensions).
- Create a spreadsheet on your computer called c:corTest.xls.
- Launch TestComplete, and open a project.
- Then click the Skull & Crossbones icon on the Extensions toolbar. Select c:corTest.xls and click OK.
You'll notice that an entry marked Corrupted_corTest.xls has been added to the Stores.Files node of your project. Browse out to your project directory and try to open Corrupted_corTest.xls. You'll see that Excel throws an error message stating that the file is corrupted.
Now you can corrupt your own files and use them as input for your own negative tests. You can reference them in code via the Files object. For example, let's say I had this JScript code, which is used to type a file name in an Open dialog:
We can tell TestComplete to use the corrupted file by changing the w2.Keys line to this:
And now TestComplete will enter the path to the corrupted file into the Open dialog.
All the source code is commented, so you can see exactly how I created this extension.
Until next time, onward automation!