Accessing Native Properties and Methods of Silverlight Objects

Applies to TestComplete 15.69, last modified on November 13, 2024

TestComplete provides you with access to individual objects of Silverlight applications, their internal properties and methods. The following sections describe how you can access these native properties and methods from your tests:

About Accessing Native Properties and Methods

TestComplete identifies individual GUI objects in Silverlight applications and provides special methods and properties for automating various operations over these objects, getting object data, checking an object's state and so on. However, if these predefined properties and methods are insufficient for your testing needs, you can use native properties and methods of Silverlight objects to complete the desired tasks. These are the same properties and methods that are available for use in the tested application’s source code, as well as custom properties and methods implemented by the application developers. This way, you can perform almost any operation in the tested Silverlight application, even those that cannot be performed via the application’s GUI.

The Object Browser marks objects of Silverlight applications with the glyph. To view native members available for a Silverlight object, use the Object Spy or Object Browser in the Advanced view mode. In the Object Browser, native properties and methods of Silverlight objects are displayed under the Silverlight category. Note that TestComplete gives access to native properties and methods of the public access type (see Important Notes for details).

Native Properties of a Silverlight Button Object in Object Browser

Click the image to enlarge it.

For more information on how to refer to objects in Silverlight applications, see Addressing Objects of In-Browser Silverlight Applications.

Note: Besides properties and methods of Silverlight GUI objects, TestComplete lets you access properties and methods of Silverlight classes defined within assemblies that are included in the tested Silverlight application package. To learn how to do that, see the Accessing Non-Visual Objects in Silverlight Applications section of the Addressing Objects of In-Browser Silverlight Applications topic.

Getting and Setting Native Object Properties

To access an object’s property in script code, you specify the property name after the object name using the dot operator "." (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "] (in C++Script and C#Script projects).

For example, you can get and set the title of a Silverlight popup window using its native Title property in the following way:

JavaScript, JScript

var title = Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title;
Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title = "New Title";

Python

title = Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title;
Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title = "New Title";

VBScript

Dim title
title = Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title
Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title = "New Title"

DelphiScript

procedure Test;
var title;
begin
  …
  title := Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title;
  Aliases.browser.page.Silverlightcontrolhost.Popup.EditOrder.Title := 'New Title';
  …
end;

C++Script, C#Script

var title = Aliases["browser"]["page"]["Silverlightcontrolhost"]["Popup"]["EditOrder"]["Title"];
Aliases["browser"]["page"]["Silverlightcontrolhost"]["Popup"]["EditOrder"]["Title"] = "New Title";

In keyword tests, you can retrieve an object’s property value and save it to a test variable using the Set Variable Value operation. To change a property value, you can use the On-Screen Action operation to call the property’s [Set] method. For more information, see Getting and Setting Object Property Values.

Saving a Silverlight object's native property value to a test variable

Click the image to enlarge it.

Setting a new value for a Silverlight object's native property

Click the image to enlarge it.

You can also create checkpoints to verify the values of native object properties.

Calling Native Object Methods

To call an object’s method from script code, you use the dot operator "." (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "] (in C++Script and C#Script projects) to specify the method name after the object name.

For example, in script code you can call the native Focus method of a Silverlight button as follows:

JavaScript, JScript

Aliases.browser.page.Silverlightcontrolhost.NewButton.Focus();

Python

Aliases.browser.page.Silverlightcontrolhost.NewButton.Focus();

VBScript

Aliases.browser.page.Silverlightcontrolhost.NewButton.Focus

DelphiScript

Aliases.browser.page.Silverlightcontrolhost.NewButton.Focus();

C++Script, C#Script

Aliases["browser"]["page"]["Silverlightcontrolhost"]["NewButton"]["Focus"]();

In keyword tests, you can use the On-Screen Action operation to call an object’s native method. For more information, see Calling Object Methods.

Invoking a Silverlight object's native method

Click the image to enlarge it.

Data Type Casting

In Silverlight, all data types are objects. As a result, there are some specifics of using values obtained from Silverlight objects in your tests:

  • Silverlight integer, double and boolean values are compatible with TestComplete data types and scripting data types, and can be directly used in tests.

  • The values of the Silverlight Decimal and DateTime objects and enumeration members should be accessed via the OleValue property. For example, you can get the window state of a Silverlight form in the following way:

    Aliases.browser.page.Silverlightcontrolhost.EditButton.Visibility.OleValue

    In certain cases, OleValue should also be used with Silverlight strings (System.String objects). For example, it may be needed to pass this value as a parameter to a user-defined script function or compare the value with another string.

Important Notes

  • In the Object Spy or Object Browser, native properties and methods of Silverlight objects are displayed only in the Advanced view mode.

  • TestComplete provides access to public native object properties, fields and methods. The members of other access types (protected, private, internal etc.) cannot be exposed.

  • If a native property or method has the same name as the test object property or method provided by TestComplete, the native property or method can be accessed via the NativeSlObject property. For example, you can access the native Name property of a Silverlight application’s button in the following way:

    JavaScript, JScript

    Aliases.browser.page.Silverlightcontrolhost.EditButton.NativeSlObject.Name

    Python

    Aliases.browser.page.Silverlightcontrolhost.EditButton.NativeSlObject.Name

    VBScript

    Aliases.browser.page.Silverlightcontrolhost.EditButton.NativeSlObject.Name

    DelphiScript

    Aliases.browser.page.Silverlightcontrolhost.EditButton.NativeSlObject.Name

    C++Script, C#Script

    Aliases["browser"]["page"]["Silverlightcontrolhost"]["EditButton"]["NativeSlObject"]["Name"]

  • The leading underscore ( _ ) in property and method names is replaced with the character z. For example, a property named _flag is accessed as zflag, a method named __reset() is accessed as z_reset(), and so on.

  • If the object contains overloaded methods (methods with the same name but different parameters and they return value types), TestComplete appends indexes to method names in order to distinguish them. For example, GetChildAtPoint() and GetChildAtPoint_2(). To determine which index-suffixed method name corresponds to which overloaded method, examine the method’s parameter list in the Object Spy, Object Browser or Code Completion.

  • Some native properties and methods of Silverlight objects are unavailable to TestComplete. For more information, see Object Properties, Fields and Methods That Are Unavailable to TestComplete.

See Also

Testing Silverlight Applications
Addressing Objects of In-Browser Silverlight Applications

Highlight search results