Turn Complex Code into a Single Button Click
Develop | Posted November 11, 2008


Transform Code into Button Clicks

Back in April, I showed you how to programmatically verify that a directory contained a certain list of files. This approach works well, but if you weren’t using JScript, or if you weren’t sure how to convert that JScript to your language of choice you would’ve been unable to take advantage of it. So I took that same code that I’d written, and bundled it up into an extension. This article shows how to take that code and turn it into an extension, which ultimately becomes the Directory Validation Checkpoint.



Planning the Checkpoint

Here are the criteria I used when planning my checkpoint:



  • Users should be able to easily select the directory whose contents they wish to validate
  • Users should have the option to include the contents of subdirectories in the validation
  • Messages should be written to the log file confirming each file that was found
  • Errors should be written to the log file for any file that was not found
  • A text file containing the directory’s contents should be created and added to the Stores node of the TestComplete project


Creating the Checkpoint

To help people easily select the directory to verify, I created this simple form in TestComplete.

This table lists the controls I placed on the form, what I named each control, and the relevant properties I set.


Object Name Properties
TcxLabel lblMessage Caption:
Select directory to be validated
TcxTextEdit txtDirectory Text
= (set to blank)
TcxButton cmdBrowseDirectory Caption
= …
TcxCheckBox chkIncludeSub Caption
= Include Subdirectories
TcxButton cmdOK

Caption = OK

ModalResult = mrOk
TcxButton cmdCancel

Caption = Cancel

ModalResult = mrCancel
TSelectDirectory dlgSelect

Caption = Select Directory to be validated

Custom Root Folder = c:



I also created an event for the cmdBrowseDirectory button, called directoryValidator_cmdBrowseDirectory_OnClick. Don’t worry about adding the code for that right now, just add the event to the button.



With the form created, I right clicked on the form and selected Export to File. I exported my form as c:directoryCheckpointdirectoryValidator.aqfrm.
Next, I took my earlier directory validation code, and modified it as below:



Creating an Icon

As I’ve stated before, drawing is not my strong suit. However, I wanted a picture of a folder to be shown on the Extension toolbar. To get that picture, I opened Windows Explorer and took a screenshot by pressing Alt+PrtScn. Then I cropped out the image I wanted, and resized it in Paint .NET down to a 16x16 bmp. Here it is:



Creating the Description File

Here’s the description file I created for this checkpoint:


Packaging the Extension

Unlike “traditional” plug-ins that need to be compiled, the extension’s source files just need to be packed into a ZIP archive. The archive extension should then be changed to tcx (TestComplete extension). That’s all, no other installation preparations are needed.
You can download the package from this link.




Using the Extension

Once the extension is installed, you can create directory validation checkpoints while you’re recording or during design time. Just click the button on the Extension tooblar to display our directory validation form. Then select the directory you want to work with and click OK. You’ll see code like this added to your script editor.
DirectoryContents.Validate("C:\Utils", Files.FileNameByName("DirListing_Utils"));



So that’s how easy it is to take code that you’ve written previously and encapsulate it into a script extension. This allows you to turn complex function calls into simple button clicks that speed up your test generation, and make automation much less daunting for non-technical users.



Until next time, onward automation!






By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox