Accessing Non-Visual Objects in .NET Applications

Applies to TestComplete 15.63, last modified on April 23, 2024

.NET applications can include non-visual components such as DataSource or ErrorProvider. These objects are not displayed in the Object Browser because they are not GUI objects. However, you can access these objects and work with them from your tests.

Accessing Non-Visual .NET Objects Through Properties of Visual Objects

You can typically access an application’s non-visual components via some properties or methods of the application’s GUI objects (see Accessing Native Properties and Methods of .NET Objects). To find the needed property or method, examine the tested .NET application in the Object Browser or ask the application developers.

For an example of accessing a non-visual object in a .NET application, see:

Working With .NET ErrorProvider

Accessing Non-Visual .NET Objects Through Static Properties and Methods

If the needed object is available via a static property or method (that is, a property or method that is associated with the object type rather than a specific object instance), you can access it using the following syntax:

JavaScript, JScript

Sys.Process("MyApp").AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

Aliases.MyApp.AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

Python

Sys.Process("MyApp").AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

Aliases.MyApp.AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

VBScript

Sys.Process("MyApp").AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

Aliases.MyApp.AppDomain("MyApp.exe").dotNET.namespace_name.class_name.property_name

DelphiScript

Sys.Process('MyApp').AppDomain('MyApp.exe').dotNET.namespace_name.class_name.property_name;

Aliases.MyApp.AppDomain('MyApp.exe').dotNET.namespace_name.class_name.property_name;

C++Script, C#Script

Sys["Process"]("MyApp")["AppDomain"]("MyApp.exe")["dotNET"]["namespace_name"]["class_name"]["property_name"]

Aliases["MyApp"]["AppDomain"]("MyApp.exe")["dotNET"]["namespace_name"]["class_name"]["property_name"]

Note: Dots in .NET namespace names are replaced with underscores ( _ ). For example, the System.Windows.Forms namespace is accessible as System_Windows_Forms.

The AppDomain object corresponds to the .NET application domain and provides access to all namespaces and classes defined in the application and its referenced assemblies.

For example, a .NET application domain includes classes from the System namespace, including the DateTime structure. This class has the static UtcNow property that returns the current UTC time, and you can use the property in your tests in the following way:

JavaScript, JScript

dateUTC = Sys.Process("Orders").AppDomain("Orders.exe").dotNET.System.DateTime.UtcNow;
Log.Message(dateUTC);

Python

dateUTC = Sys.Process("Orders").AppDomain("Orders.exe").dotNET.System.DateTime.UtcNow;
Log.Message(dateUTC);

VBScript

dateUTC = Sys.Process("Orders").AppDomain("Orders.exe").dotNET.System.DateTime.UtcNow
Log.Message dateUTC

DelphiScript

dateUTC := Sys.Process('Orders').AppDomain('Orders.exe').dotNET.System.DateTime.UtcNow;
Log.Message(dateUTC);

C++Script, C#Script

dateUTC = Sys["Process"]("Orders")["AppDomain"]("Orders.exe")["dotNET"]["System"]["DateTime"]["UtcNow"];
Log.Message(dateUTC);

In keyword tests, you can access the AppDomain object as well as the underlying .NET namespace, classes, properties and methods using the On-Screen Action or Call Object Method operation, as shown in the image below. For this purpose, specify the .NET class name in the above syntax as the target object name. Then select the needed property or method as the target operation.

Using .NET non-visual DateTime component in a keyword test

See Also

Testing .NET Applications
About Testing .NET Applications
Addressing Objects in .NET Applications
Accessing Native Properties and Methods of .NET Objects

Highlight search results