Addressing Objects of Out-of-Browser Silverlight Applications

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

The information in this topic applies to web tests that locate web objects by using internal identification properties provided by TestComplete and run in local environments.

This topic explains how TestComplete names objects of out-of-browser Silverlight applications exposed via the UI Automation engine and how you can address these objects in your tests.

General Notes

Out-of-browser Silverlight applications are launched with a special helper utility - Microsoft Silverlight Out-of-Browser Launcher (sllauncher.exe). This utility contains the WebBrowser control which displays a wrapper page for the Silverlight application. So, out-of-browser Silverlight applications behave like ordinary desktop applications.

Addressing windows, controls and objects in applications is hierarchical. That is, to obtain an object of a Silverlight out-of-browser application, you should first obtain the sllauncher process and the page that hosts the tested application, then access the application itself and finally obtain the desired object. To learn the object hierarchy and names in the tested Silverlight application, you can explore it in the Object Browser(see the next section of this topic).

You can also learn the object names by recording actions over the desired objects and viewing the names in the recorded script or keyword test.

Moreover, an easy way to learn how a particular element can be addressed and to explore the element’s properties, fields and methods is to use the TestComplete target glyph:

  • Click the  Display Object Spy button on the Tools toolbar.

  • In the Object Spy window, click the Drag the target to point to the object icon and drag its glyph () to the desired object. As you move the mouse pointer, a red frame appears around the element under the pointer. Release the mouse button over the desired element. TestComplete will display the element’s name, properties, methods and events in the Object Spy window.

Exploring Silverlight Applications in the Object Browser

When the tested Silverlight application is exposed by the UI Automation engine, TestComplete can obtain scripting access to the application’s visual objects and provide special properties and methods for working with these objects. You can easily learn what properties and methods are available to your tests by exploring the application in the Object Browser panel:

  1. Launch your out-of-browser application.

  2. Expand the node that corresponds to the sllauncher process and its child nodes in the Object Browser until you reach the node corresponding to the tested Silverlight application.

    The Object Browser Displaying an out-of-browser Silverlight Application

    The objects of a Silverlight Application are displayed in the Object Browser with the icon. They are addressed by calling the UIAObject() method (see below).

  3. When you select the needed Silverlight object in the Object Browser, you can explore its properties and methods on the Properties and Methods tabbed pages of the Object Browser, respectively. Here, in the UI Automation group, you can see the properties and methods provided by the UI Automation engine.

Addressing Silverlight Objects Using Name Mapping

By default, TestComplete uses object names from the Name Mapping project item to refer to individual objects in a tested application. Using Name Mapping you can assign custom names to the application’s objects and then address mapped objects in your tests using these custom names instead of fully-qualified names.

You can see custom mapped names and aliases in the Name Mapping Editor:

Sample Name Mapping for an out-of-browser Silverlight application

Click the image to enlarge it.

Here, Mapped Objects and Aliases display the hierarchy of mapped objects and their aliases, respectively. The full name that can be used to refer to an object is displayed in the top right part of the Name Mapping editor. For example, in the image above you can see that you can refer to the ContactListBox object using the following name:

VBScript

Aliases.sllauncher.Silverlight_Control.ContactListBox

Note that the mapped name for this object is the following:

VBScript

NameMapping.Sys.sllauncher.wndAfx.ShellEmbedding.ShellDocObjectView.browser.Silverlight_Control.ContactListBox

The highlighted objects (wndAfx, ShellEmbedding, ShellDocObjectView and browser) are not crucial for our test, so we have excluded them from the path to the ContactListBox object in the Alias tree. This is one of the benefits of the aliases notation - shorter and more readable scripts.

For more information about using Name Mapping and aliases, see Name Mapping and Access Objects by Aliases.

Addressing Silverlight Objects Without Name Mapping

Your tests can work not only with applications and objects added to Name Mapping, but also with any other running applications, their windows and controls. These objects can be addressed by using a syntax that directly includes identification property values.

Keyword test operation on an out-of-browser Silverlight object that is not in Name Mapping

The sample code below demonstrates how you can refer to an object in your out-of-browser Silverlight application:

JavaScript, JScript

Sys.Process("sllauncher").Window("Afx:*", "*").Window("Shell Embedding").Window("Shell DocObject View").Window("Internet Explorer_Server").Page("*").Panel("silverlightControlHost").Object("sl").UIAObject("ContactListBox").Click();

Python

Sys.Process("sllauncher").Window("Afx:*", "*").Window("Shell Embedding").Window("Shell DocObject View").Window("Internet Explorer_Server").Page("*").Panel("silverlightControlHost").Object("sl").UIAObject("ContactListBox").Click();

VBScript

Call Sys.Process("sllauncher").Window("Afx:*", "*").Window("Shell Embedding").Window("Shell DocObject View").Window("Internet Explorer_Server").Page("*").Panel("silverlightControlHost").Object("sl").UIAObject("ContactListBox").Click

DelphiScript

Sys.Process('sllauncher').Window('Afx:*', '*').Window('Shell Embedding').Window('Shell DocObject View').Window('Internet Explorer_Server').Page('*').Panel('silverlightControlHost').Object('sl').UIAObject('ContactListBox').Click();

C++Script, C#Script

Sys["Process"]("sllauncher")["Window"]("Afx:*", "*")["Window"]("Shell Embedding")["Window"]("Shell DocObject View")["Window"]("Internet Explorer_Server")["Page"]("*")["Panel"]("silverlightControlHost")["Object"]("sl")["UIAObject"]("ContactListBox")["Click"]();

To learn the exact syntax for referring to a particular object, use the Object Browser - it always uses this syntax for object names.

Let’s have a closer look at this notation and its components.

  • The notation starts with the Sys object that represents the operating system.

  • The next object, Process("sllauncher"), represents the launcher utility used to run the tested application in out-of-browser mode.

  • The next four Window objects correspond to the parent windows of the embedded WebBrowser control.

  • The Page(URL)object is the container web page that hosts the tested application.

  • The next two objects, Panel("silverlightControlHost") and Object("sl"), correspond to the tested application’s main object and web page element that contains it.

    • The first object, Panel("silverlightControlHost"), corresponds to the DIV element of the web page.
    • The second, Object("sl"), corresponds to the OBJECT element that embeds the Silverlight application. This is the main object of the tested application.
  • The other objects represent visual objects in the Silverlight application.

    TestComplete uses the following syntax for these objects:

    UIAObject(ObjectIdentifier, [Index])

    Here, ObjectIdentifier is an identifier that is used to name a UI Automation element. This can be one of the following:

    • The object name as it is specified in the tested application’s source code
    • The UI Automation identifier (AutomationId) for the element. (If the object name is not specified.)
    • The object’s class name. (If neither the object name, nor the Automation identifier is specified.)

    To learn the identifier of the current object, refer to the ObjectIdentifier property.

    The Index parameter is used only if the object contains two or more child objects that have the same class name and caption.

    Also, the WaitUIAObject method can be used to address the objects exposed by the UI Automation engine. It is similar to the UIAObject method, but delays the script execution until the specified visual object appears or until the specified timeout elapses.

For examples of this syntax used for objects in your tested Silverlight application, examine your application in the Object Browser. You can also copy this syntax from the Object Browser and paste it to your test in order not to type it manually.

Combining Mapped and Unmapped Object Names

You can combine aliases specified in Name Mapping and the UIAObject notation when referencing the object hierarchy in tests. For example, you can use aliases for parent objects and the UIAObject notation for child objects:

VBScript

Call Aliases.sllauncher.objectSl.UIAObject("Save").Click

However, keep in mind that aliases must always precede the UIAObject notation in the object hierarchy. Aliases cannot be used after the UIAObject notation within the same statement. That is, the following statement is invalid:

VBScript

Call Sys.Process("sllauncher").Window("Afx:*", "*").Window("Shell Embedding").Window("Shell DocObject View").Window("Internet Explorer_Server").Page("*").Panel("silverlightControlHost").Object("sl").UIAObject("ScrollViewer").Item_1.Click

See Also

Testing Out-of-Browser Silverlight Applications
Testing Silverlight Applications

Highlight search results