A New "Wait For Object" Script Extension For TestComplete

About the "Wait For Object" Extension

Some TestComplete users have problems with writing the "wait for object" and "if object exists" code. Although there is a Waiting Objects screencast, a Waiting Objects FAQ entry and help topics devoted to this question, it still appears quite often in TestComplete forums. In order to help our users, we created the Wait For Object script extension for TestComplete, which automatically generates the wait code for the selected object, for example:

if(!Sys.WaitProcess("notepad", 5000).Exists)

Log.Error("The object was not found within 5000 ms.", "Sys.Process("notepad")");

The extension can be downloaded from here:Wait For Object Script Extension.

Installing the Extension

There are two ways to install the extension in TestComplete:

  • Double-click the WaitForObject.tcx file in a file manager and choose the folder where it should be installed. The default path is <TestComplete>BinExtensionsScriptExtensions.
  • Manually copy the WaitForObject.tcx file to the <TestComplete>BinExtensionsScriptExtensions folder or any other folder specified in TestComplete's Engines | Script Extensions settings.

Note: If TestComplete is running, you'll need to reload the available script extensions. To do this, select File | Install Script Extensions in TestComplete's menu and click Reload.

Using the Extension

Once the extension is installed, you will notice the Wait For Object item in the list of custom actions on TestComplete's Recording and Tools toolbars:

'Wait For Object' command on Recording toolbar

'Wait For Object' command on Tools toolbar

Selecting this command will bring up a wizard where you can visually specify the checkpoint options:

Create 'Wait For Object' Checkpoint dialog

The wizard works in two modes: it can target either on onscreen objects (windows, controls, etc) or processes (Sys.Process("...") objects). To pick an onscreen object, choose Onscreen object as the object type, then drag the Finder glyph (Finder tool) to the desired object and drop it when the red frame appears around that object. To select a process, choose Process as the object type and then pick any window or onscreen object that belongs to that process. The name of the selected object will be displayed in the text box next to the Finder.

The checkpoint timeout is specified in milliseconds. For example, 10000 means 10 seconds. To wait for an object to become available, specify a non-zero timeout; at that, -1 means infinite waiting time. To check if an object exists or not, specify 0 as a timeout. This will make TestComplete check for the object existence only once and return the result immediately.

After you have specified all the options, click OK to generate the "wait" code and exit the wizard. If you are creating the checkpoint at design time, then you'll also get a preview of the generated code and will be able to copy this code to the clipboard or insert it directly to your script:

Add Code to Test dialog

Conclusion

Script extensions can help you reduce various test creation tasks to a few button clicks. For example, they can generate script code for you, as does the Wait For Object extension described in this article. I hope this extension saves you time on test creation, which you'll be able to spend on new tests or a cup of coffee ;-). As always, you're welcome to leave comments and suggestions.

 


Close

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