Real-world TestComplete Plug-ins, Part I

A string utilities plug-in

I love products with extensibility. Obviously, a product must work well right out-of-the-box, but assuming that precondition,
that a product works the way it should, my next feature request is that it have some sort of plug-in API.
AutomatedQA products, of course, have this almost to excess. With version 4 of TestComplete, the plug-in API
was largely rewritten, requiring all my TestComplete 3 plug-ins to be reworked. At first, I wasn't too happy
about this, but I'm finally starting to make some progress with the new SDK, and my plug-ins are again taking shape.
As a result, I've decided to share what I'm learning, and to share the results of my efforts as well. This is the first
of what will (hopefully) be a multi-part series on creating plug-ins for TestComplete 4. These articles/plug-ins will consist
of my actual completed custom plug-ins with an install for adding them to TestComplete, a help file, source code and an article
that discusses what I learned as I worked on the project. I'll do this in ascending order of complexity; for example, today's
project is a very simple plug-in that basically provides a library of common routines. The next project will demonstrate the
process of having your plug-in listen for TestComplete events.

Plug-ins series:

Part I - Basics; a common routine library - String Utilities plug-in

Part II - Implementing an events listener - CodeSite plug-in

Part III - Plug-in panels - extended colors plug-in
More…


A few more thoughts:

This article is not a tutorial into the basics and inner workings of the TestComplete plug-in SDK.
AutomatedQA has provided some materials on that (including, by the way, an SDK help file that gets
installed to your C:Program FilesAutomated QATestComplete 4Help directory when you install the SDK -
important to note). Plan on researching the provided SDK and on digging through the TestComplete and
TestCompleteInternal type libraries; this is where I've gotten most of my information. If you're not
familiar with the published SDK, you should probably do some reading, but even without that, you can get
something out of these articles - and at the very least, you can just install and use the plug-ins.

So, without further ado…

A Common Routines Plug-in

Our first plug-in is one that simply provides a library of common routines. A question that came up repeatedly
when I was with AutomatedQA was how to best manage sets of common or shared routines. There are pluses and minuses
to the various (see my previous article: To Plug-in or Not to Plug-in)
but the plug-in approach has advantages in that it offers ease of deployment and ease of use - no need to add units to
projects or to make sure that you have the latest version of an ODT object. With a plug-in, the functionality is literally built into TestComplete.
With this in mind, I've implemented a set of odd string management routines as a simple runtime plug-in.

"Runtime plug-in"?

This is probably a good time to remind you of some of the architecture changes in version 4 of the TestComplete SDK.
The new version does a particularly good job of enforcing the separation of plug-in registration, design-time and run-time parts of the plug-ins.
For instance, registration is the part of your extension that registers the plug-in with TestComplete - telling it
how to find and create the actual plug-in object when it needs it…

Such as when it's being referenced in design-time: does it have settings (options)? Does it provide a scripting interface
(does it appear in the code completion window)? Does it have panels that appear in the TestComplete IDE?.
In the case of the string utilities plug-in, it needs to run at runtime; it needs to provide information to the code completion
window, but that's about it. No panels, no settings, no event listening… nothing fancy.
You'll note that the SDK samples provided by AutomatedQA are available for either Delphi or MS Visual C++. No C# at this time.
As a result, I'm creating my plug-ins in Delphi.

Here's an overview of the entities in the plug-in project. Make sure you read both this article and the TestComplete
SDK documents to get a good feel for what's going on.

In addition to the entity overview, I'm including this simple sequence diagram to help explain some of the responsibilities of the various objects in the string utilities plug-in project.

ItsStringUtils

This is the interface that describes what the tsStrUtils plug-in makes available for scripting purposes.

For this particular plug-in, there are only methods (operations).

StrUtils Interface

You can see that this is the same list that appears in the code completion window:

Code Completion
TtsStrRuntimeObj

TtsStrRuntimeObj is the object that handles the implementation of the script calls to the StrUtils object when a test is playing back. If TestComplete needs to call methods of your plug-in, it creates an instance of your plug-in's runtime object; see the SDK interface ItcRuntimeObjectFactory and its CreateRuntimeObject method - this interface and method is implemented by the plugin object; in this case that's the TtsStrUtilsPlugin.CreateRuntimeObject method. You can find that in the source code of this article. Note that in the case of this plug-in, the TtsStrUtilsPlugin class is basically a pass-through to the TtsStringUtils static class found in tsUtilityClasses.pas. This is a collection of string utilities I've been using for years. I wrote some of them, others are from code I've picked up over time and, unfortunately, have lost the origin. I wish to correctly credit those who wrote the code, so if you recognize any of it, please let me know. In any case, it's some common routines - the point is that you can take the same approach with your own libraries.

TtsStrUtilsPlugin

This is the class that is considered the actual "plug-in" object. In the case of this plug-in, there's not just a great deal to it; it basically tells TestComplete some information about itself and where to get the runtime object.

TtsStrPluginRegistrator

You can find out just about everything you need to know about this Registrator class by reading the SDK docs. This object takes care of registering the actual plug-in with TestComplete.

Using the String Utilities plug-in

Making use of the plug-in could not be simpler. Once it's installed, the methods of the StrUtils plug-in are available to you via the code completion window in TestComplete. You can make use of them in the same way you would any other object in TestComplete. There are comments about the methods in the code completion window, and I've provided a help file too, as part of the install.


You can find the install file at http://www.automatedqa.com/images/blog/rkl_tsStrUtilsSetup.zip


Close

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

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