Creating Connected Applications in Visual Basic .NET

Applies to TestComplete 14.60, 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 .NET. To learn how to do this in Visual Basic 6.0, see Creating Connected Applications in Visual Basic.

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

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

The description of each step is below.

Adding modules to your Visual Basic .NET project

  • Create a new Visual Basic .NET project or open an existing project in Visual Studio .NET (Visual Studio 2005).

  • In Visual Studio .NET 7.x. select Project | Add Reference from the main menu to display the Add Reference dialog. Go to the .NET tabbed page and click the Browse button to display the standard Open File dialog and open the AutomatedQA.TestComplete.VBConnectedApp.dll library (by default, it is located in the <TestComplete>\Connected Apps\.NET folder). After you have added this library to the component list, click OK to close the Add Reference dialog.

  • In Visual Studio 2005, do the following:

    • Rightlick your project in the Solution Explorer and then select Add Reference from the context menu.

    • In the resulting Add Reference dialog, switch to the Browse tabbed page.

    • Open the AutomatedQA.TestComplete.VBConnectedApp.dll library (by default, it is located in the <TestComplete>\Connected Apps\.NET folder).

    • Click OK to close the Add Reference dialog.

Writing test code in your Visual Basic .NET Connected Application

  • Add the following string to the beginning of the source file, which will hold the test code:

    Visual Basic .NET

    Imports AutomatedQA.TestComplete.Connect

  • To create test code in a Connected Application, you can either write the test code into your Visual Basic .NET source, or copy the test procedure(s) from TestComplete scripts written in VBScript.

    To address TestComplete global programming objects, use their names. However, this functionality is only supported for TestComplete standard objects (Sys, Log, Regions and others). To address objects provided by third-party plugins, use the TC.Integration.GetObjectByName method of the Connect class:

    Visual Basic .NET

    Imports AutomatedQA.TestComplete.Connect
    ...
    MyObj = TC.Integration.GetObjectByName("MyObjectName")

  • Important: make sure your VB.NET units do not contain the Option Strict On statement. This statement forbids late binding which is needed to execute the imported script code.

  • 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. So, to run the test code, you should either launch the Connected Application from the TestComplete script, or call the Connect.RunTest routine (see Running Connected and Self-Testing Applications for more information).

    So, if you are going to use the Connect.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 Connect.RunTest, use the Connect.StopTest routine:

    Visual Basic .NET

    Connect.RunTest("My Test", "MyProject", "C:\Work\MyProjectSuite.pjs")
    ...
    ' Test code
    ...
    Connect.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 the Connected Application 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 Connect.RunTest routine (see Running Connected and Self-Testing Applications).

If you do not use the Connect.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 perform 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 6.0
Creating Self-Testing Applications in Visual Basic .NET

Highlight search results