8. Adding Methods' Definitions to the Description File

Applies to TestComplete 15.47, last modified on January 20, 2023

After writing code for the object’s methods, we need to add information about the methods to the description.xml file:

  1. Open the C:\My Extension Files\Object Extension\description.xml file in any text or XML editor.

  2. Add the following text to the file:

    XML

    [description.xml]

    <?xml version="1.0" encoding="UTF-8"?>
    <ScriptExtensionGroup>

      <Category Name="Runtime Objects">

        <ScriptExtension Name="WMI Object" Author="SmartBear Software" Version="1.1 test" HomePage="smartbear.com">
          <Script Name="wmiCode.vbs" InitRoutine="Initialize">
            <RuntimeObject Name="WMI">
              <Method Name="ConnectToComputer" Routine="ConnectToComputer">
                Connects to WMI on the specified computer using the specified user name and password.
              </Method>
              <Method Name="WaitForComputer" Routine="WaitForComputer">
                Waits until the WMI connection to the specified computer is established during a timeout period.
              </Method>
              <Method Name="RestartComputer" Routine="RestartComputer">
                Restarts the computer.
              </Method>
              <Method Name="CreateProcess" Routine="CreateProcess">
                Launches the specified process.
              </Method>
              <Method Name="ProcessExists" Routine="ProcessExists">
                Checks if the specified process is running.
              </Method>
              <Method Name="WaitForProcessExit" Routine="WaitForProcessExit">
                Waits for a process to end during a timeout period.
              </Method>
              <Method Name="GetServiceState" Routine="GetServiceState">
                Returns the current state of the specified service.
              </Method>
              <Method Name="WaitForServiceState" Routine="WaitForServiceState">
                Waits for a service state to change during a timeout period.
              </Method>
              <Method Name="GetEnvironmentVariable" Routine="GetEnvironmentVariable">
                Returns the value of the specified environment variable.
              </Method>
              <Method Name="PostEnvironmentVariableInfo" Routine="PostEnvironmentVariableInfo">
                Logs information about environment variables.
              </Method>
              <Method Name="PostProcessorInfo" Routine="PostProcessorInfo">
                Logs information about the processor(s) installed on the computer.
              </Method>
              <Method Name="PostDrivesInfo" Routine="PostDrivesInfo">
                Logs information about disk drives available on the computer.
              </Method>
              <Method Name="PostInstalledAppsInfo" Routine="PostInstalledAppsInfo">
                Logs information about all the applications installed on the computer.
              </Method>
              <Method Name="PostEventsInfo" Routine="PostEventsInfo">
                Posts information from the system event log to the test log.
              </Method>

              <Property Name="ComputerName" GetRoutine="GetComputerName" SetRoutine="SetComputerName">
                The name of the computer that the WMI object works with. A dot (".") stands for the local computer.
              </Property>
              <Property Name="Service" GetRoutine="GetWMIService">
                Returns the WMI service object.
              </Property>
              <Property Name="MaxEventCount" GetRoutine="GetMaxEventCount" SetRoutine="SetMaxEventCount">
                Specifies the maximum number of entries to be retrieved from the system event log.
              </Property>
              <Description>
                Provides access to the WMI service.
              </Description>
            </RuntimeObject>
          </Script>
          <Description>
            Provides scripting interface to WMI objects.
          </Description>
        </ScriptExtension>

      </Category>

    </ScriptExtensionGroup>

  3. Save the changes.

As you can see, to define methods of the object, we added child Method elements to the RuntimeObject element.

The Method elements correspond to individual methods of the object. We added one Method element for every method of the object. Those script routines that are not declared in the description file will not be accessible outside of the object.

Let’s look at one of the Method elements:

XML

[description.xml]

<Method Name="ConnectToComputer" Routine="ConnectToComputer">
  Connects to WMI on the specified computer using the specified user name and password.
</Method>

The Name attribute specifies the method name that will be used to call the method. In our example, the method name is ConnectToComputer.

The Routine attribute specifies the name of the script routine that belongs to the wmiCode unit and that will be executed when users call the WMI.ConnectToComputer method in their tests.

The contents of the Method element (text) is used as the method’s description. It is displayed, for instance, in the Code Completion window when a user selects the method in it.

Note that there is no need to define the method parameters in the description file as TestComplete automatically learns them from declarations of the corresponding script routines in the source code.

Prev     Next

See Also

Structure of the Description File

Highlight search results