Creating Connected Applications in Visual Basic 6.0

Applies to TestComplete 14.50, last modified on April 22, 2021
Information in this topic applies to desktop applications only.
Connected and Self-Testing applications are deprecated. These technologies will be removed in one of the future releases of TestComplete.
To create test code that runs from within your tested apps, use TestLeft, a SmartBear functional testing tool for developers.

This topic explains how to create a Connected Application in Visual Basic 6.0. To learn how to do this in Visual Basic .NET, see Creating Connected Applications in Visual Basic .NET.

Creation of a Visual Basic Connected Application includes the following steps:

  • Adding modules to your Visual Basic project
  • Writing test code in your Visual Basic Connected Application
  • (Optional) Writing code in your TestComplete project

The description of each step is below.

Note: Visual Basic Connected Applications require the TlbInf32.dll file to be installed on your computer. By default, it is placed in your Windows System or System32 folder by the TestComplete installation.

Adding modules to your Visual Basic project

  • Create a new project or open an existing one in Visual Basic.

  • Add the TCConnect.bas module to the project. This file is located in the <TestComplete>\Connected Apps\VB directory. To add the file to your project, select the Project | Add Module menu item in Visual Basic.

Writing test code in your Visual Basic Connected Application

To create test code in Connected Applications, write the test code into your Visual Basic source, or copy the test procedure(s) from TestComplete scripts written in VBScript.

Use object names to address TestComplete objects from a Connected Application. This functionality is only implemented for standard TestComplete objects (Sys, Log, Regions, Files and others) and not supported for objects that are provided by third-party plugins.

If you need to work with objects that are provided by third-party plugins, you should obtain this object in your code by using the TC.Integration.GetObjectByName method (the TC is defined in TCConnect.bas). To emulate addressing of an object by its name, you can create special function that will call the GetObjectByName function and return the desired object. The important thing is that the function’s name coincides with the object’s name:

Visual Basic

[YourUnit.bas]
 

...
Public Function MyObjectName() As Object
  Set MyObjectName = TC.Integration.GetObjectByName("MyObjectName")
End Function

Since Visual Basic lets you skip braces when calling functions that do not have any parameters, the function will give an impression that you address an object directly.

Note that in order for the Connected Application to be able to address TestComplete objects and post messages to the test log, TestComplete must be in the script-running mode. To run the test code, you should either launch the Connected Application from the TestComplete script, or call the RunTest routine (see Running Connected and Self-Testing Applications for more information).

So, if you are going to use the RunTest routine, insert a call to it before the first statement of the test code in your Connected Application. To stop the test run initiated with RunTest, use the StopTest routine:

Visual Basic

RunTest "My Test", "MyProject", "C:\Work\MyProjectSuite.pjs"
...
' Test code
...
StopTest

If you are going to launch your Connected Application from TestComplete, call the test procedure from your own code. For instance, you can call the test procedure within a button’s OnClick event handler.

Compile your application.

Writing code in your TestComplete project

In order for Connected Applications to be able to use TestComplete scripting objects and post messages to the test log, TestComplete must be in the script-running mode. The testing engine switches to this mode when you run a test from TestComplete, or when you call the RunTest routine (see Running Connected and Self-Testing Applications).

If you do not use the RunTest routine, you should launch your Connected Application from TestComplete. To do this:

  • Open your project in TestComplete.

  • Add your Connected Application to the project’s tested applications list. For more information on how to do this, see Defining Applications to Test.

  • Write script code that will launch your Connected Application and wait while it performs the testing actions. For instance:

    JavaScript, JScript

    function Test()
    {
      var p;
      // Launches the Connected Application and obtains the process
      // that corresponds to your Connected Application
      p = TestedApps.Items(0).Run();
      // Delays script execution while 
      // the Connected Application performs the testing actions
      while(p.Exists)
        aqUtils.Delay(500);
    }

    Python

    def Test():
      # Launches the Connected Application and obtains the process
      # that corresponds to your Connected Application
      p = TestedApps.Items[0].Run()
      # Delays script execution while 
      # the Connected Application performs the testing actions
      while(p.Exists):
        aqUtils.Delay(500)

    VBScript

    Sub Test
      ' Launches the Connected Application and obtains the process
      ' that corresponds to your Connected Application
      Set p = TestedApps.Items(0).Run
      ' Delays script execution while
      ' the Connected Application performs the testing actions
      While p.Exists
        aqUtils.Delay 500
      WEnd
    End Sub

    DelphiScript

    procedure Test;
    var
      p : OleVariant;
    begin
      // Launches the Connected Application and obtains the process
      // that corresponds to your Connected Application
      p := TestedApps.Items[0].Run;
      // Delays script execution while
      // the Connected Application performs the testing actions
      while p.Exists do
        aqUtils.Delay(500);
    end;

    C++Script, C#Script

    function Test()
    {
      var p;
      // Launches the Connected Application and obtains the process
      // that corresponds to your Connected Application
      p = TestedApps["Items"](0)["Run"]();
      // Delays script execution while 
      // the Connected Application performs the testing actions
      while (p["Exists"])
        aqUtils["Delay"](500);
    }
  • Make sure this code is called when running the current TestComplete project.

  • As you can see, the script is running until the Connected Application is closed. In order to stop the script run from the Connected Application, use the Runner.Stop method. This method notifies TestComplete that the run is over and refreshes the Test Log so that it displays the latest test results.

You can now run the test by clicking the button whose OnClick event handler contains the test code.

See Also

Connected Applications - Overview
Creating Event Handlers in Visual Basic 6.0 Applications
Running Connected and Self-Testing Applications
Self-Testing Applications
Creating Connected Applications in Visual Basic .NET
Creating Self-Testing Applications in Visual Basic .NET

Highlight search results