Generating Process, Window and Onscreen Object References

Applies to TestComplete 15.70, last modified on December 17, 2024

Custom actions created with script extensions can generate code that addresses the processes running on the local computer and the connected portable device as well as windows and objects of these processes. To generate an expression that references a Sys, process, window or onscreen object, simply obtain this object as you would do this in an ordinary TestComplete script. You can then use this object as part of a more complex expression or statement, for example, as an object to call a method on.

The described technique works only if the target object exists in the system at the moment. Otherwise, you will have to generate the desired expression by invoking syntax elements (see Generating Object Method Calls).

The following sample code generates the code that references the FileVersionInfo property of the TestComplete process. For more information on generating object property expressions, see Generating Object Property Expressions.

JScript

function ShowMethodCallStatement()
{
    var oPropName = Syntax.CreateInvoke();
    oPropName.ClassValue = Sys.Process("TestComplete");
    oPropName.InvokeName = "FileVersionInfo";
    oPropName.IsProperty = true;

    var strCode = Syntax.GenerateSource(oPropName);
    aqDlg.ShowMessage(strCode);
}

VBScript

Sub ShowMethodCallStatement
    Dim oPropName, strCode

    Set oPropName = Syntax.CreateInvoke
    oPropName.ClassValue = Sys.Process("TestComplete")
    oPropName.InvokeName = "FileVersionInfo"
    oPropName.IsProperty = True

    strCode = Syntax.GenerateSource(oPropName)
    aqDlg.ShowMessage strCode
End Sub

The generated code is as follows:

JavaScript, JScript

Sys.Process("TestComplete").FileVersionInfo;

Python

Sys.Process("TestComplete").FileVersionInfo

VBScript

Sys.Process("TestComplete").FileVersionInfo

DelphiScript

Sys.Process('TestComplete').FileVersionInfo;

C++Script, C#Script

Sys["Process"]("TestComplete")["FileVersionInfo"];

Note, that if the object being referenced has a mapped name or alias in the user’s current project, the generated code will address the object by that mapped name (alias). For example, assuming that the TestComplete process is mapped and has the TC alias, the example above will generate the following code:

JavaScript, JScript

Aliases.TC.FileVersionIfno;

Python

Aliases.TC.FileVersionIfno;

VBScript

Aliases.TC.FileVersionIfno

DelphiScript

Aliases.TC.FileVersionIfno;

C++Script, C#Script

Aliases["TC"]["FileVersionIfno"];

See Also

Generating Script Code
Generating Object Property Expressions
Generating Object Method Calls
Sys Object
Process Object
Window Object
Onscreen Object

Highlight search results