Testing Silverlight Applications - Overview

Applies to TestComplete 15.63, last modified on April 23, 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.

TestComplete provides full support for automated testing of applications based on the Microsoft Silverlight technology. The following topic provides a brief overview of testing Silverlight applications with TestComplete.

An Overview of Supported Silverlight Technologies

Silverlight applications are Rich Internet Applications (RIA) which are executed in web browsers. In-browser mode is the essential and most common way to use them. With TestComplete you can test applications created with Silverlight 4 - 5 and running within the following web browsers:

  • Microsoft Internet Explorer ver. 11, including Silverlight 5 applications running in 64-bit versions of Internet Explorer.

  • Any web browser based on the Microsoft WebBrowser control (but not the Edge-based WebBrowser control) .

Microsoft has added the ability to deploy a Silverlight application on a local computer. Such applications are called Out-of-Browser Silverlight Applications. TestComplete can test Out-of-Browser Silverlight Applications, however it uses another testing approach and obtains less access to the application internals. You can also use the same approach to test Silverlight applications running in Firefox.

Approaches to Testing Silverlight Applications

To test Silverlight applications, TestComplete needs to get scripting access to the applications’ internals. Currently, you can get access to Silverlight applications and make them testable in two ways.

  • When a Silverlight application is running in one of the supported browsers, TestComplete automatically exposes its internal objects, methods and properties. In more complex cases, (for instance when HTTPS or cross-domain communication is used), you need to prepare your Silverlight application for testing. For more information on this, see Preparing In-Browser Silverlight Applications for Testing.

    Once a Silverlight application is treated as an Open Application, TestComplete can identify all the objects in the application, record and play back user interactions with them.

  • To test Silverlight applications running in Firefox and out-of-browser Silverlight applications, use the functionality provided by the UI Automation engine. However, in this case, TestComplete only partially exposes the controls of Silverlight applications and does not provide scripting access to the applications’ native objects and their members.

Further information of this section relates to testing of in-browser Silverlight applications. To learn about testing of out-of-browser Silverlight applications, see the Using Microsoft UI Automation Technology section.

Preparing the Testing Environment

In order to test a Silverlight application, you need to properly configure your testing environment. This may include preparing the application to be tested, changing some web browser settings, and so on. For a complete checklist, see the following topics:

Creating and Recording Tests for Silverlight Applications

With TestComplete, you can record and play back user actions in Silverlight applications, or you can create tests manually from scratch. Usually, it is easier to record the test first and then modify and enhance the recorded test.

When you record a test, you interact with the tested Silverlight application as an end-user would: navigate through the application’s screens, fill out forms and so on. TestComplete captures all actions you perform in the application and adds them to the test.

A test consists of a sequence of operations that define various interactions with objects in the tested application. For example, in the sample test below you can see that item selection from a combo box is represented by the ClickItem operation, clicking a button - by the ClickButton operation, and so on.

Sample keyword test recorded against a Silverlight application
Sample keyword test recorded against a Silverlight application

JavaScript, JScript

function Test1()
{
  var browser;
  var vobject;
  var editOrder;
  var textBox;
  browser = Aliases.browser;
  browser.ToUrl("http://secure.smartbearsoftware.com/samples/testcomplete15/silverlight/orders.html");
  vobject = browser.pageOrders.Form.Silverlightcontrolhost.object;
  vobject.NewButton.ClickButton();
  editOrder = vobject.Popup.EditOrder;
  editOrder.ProductComboBox.ClickItem("FamilyAlbum");
  textBox = editOrder.cname;
  textBox.Click(17, 11);
  textBox.SetText("Bender Rodriguez");
  editOrder.OKButton.ClickButton();
}

Python

def Test1():
  browser = Aliases.browser;
  browser.ToUrl("http://secure.smartbearsoftware.com/samples/testcomplete14/silverlight/orders.html");
  vobject = browser.pageOrders.Form.panelSilverlightcontrolhost.object;
  vobject.NewButton.ClickButton;
  editOrder = vobject.Popup.EditOrder;
  editOrder.ProductComboBox.ClickItem("FamilyAlbum");
  textBox = editOrder.cname;
  textBox.Click(17, 11);
  textBox.SetText("Bender Rodriguez");
  editOrder.OKButton.ClickButton;

VBScript

Sub Test1
  Dim browser
  Dim vobject
  Dim editOrder
  Dim textBox
  Set browser = Aliases.browser
  Call browser.ToUrl("http://secure.smartbearsoftware.com/samples/testcomplete15/silverlight/orders.html")
  Set vobject = browser.pageOrders.Form.Silverlightcontrolhost.object
  vobject.NewButton.ClickButton
  Set editOrder = vobject.Popup.EditOrder
  Call editOrder.ProductComboBox.ClickItem("FamilyAlbum")
  Set textBox = editOrder.cname
  Call textBox.Click(17, 11)
  Call textBox.SetText("Bender Rodriguez")
  editOrder.OKButton.ClickButton
End Sub

DelphiScript

procedure Test1;
  var browser : OleVariant;
  var vobject : OleVariant;
  var editOrder : OleVariant;
  var textBox : OleVariant;
begin
  browser := Aliases.browser;
  browser.ToUrl('http://secure.smartbearsoftware.com/samples/testcomplete15/silverlight/orders.html');
  vobject := browser.pageOrders.Form.panelSilverlightcontrolhost.object;
  vobject.NewButton.ClickButton;
  editOrder := vobject.Popup.EditOrder;
  editOrder.ProductComboBox.ClickItem('FamilyAlbum');
  textBox := editOrder.cname;
  textBox.Click(17, 11);
  textBox.SetText('Bender Rodriguez');
  editOrder.OKButton.ClickButton;
end;

C++Script, C#Script

function Test1()
{
  var browser;
  var vobject;
  var editOrder;
  var textBox;
  browser = Aliases["browser"];
  browser["ToUrl"]("http://secure.smartbearsoftware.com/samples/testcomplete15/silverlight/orders.html");
  vobject = browser["pageOrders"]["Form"]["panelSilverlightcontrolhost"]["object"];
  vobject["NewButton"]["ClickButton"]();
  editOrder = vobject["Popup"]["EditOrder"];
  editOrder["ProductComboBox"]["ClickItem"]("FamilyAlbum");
  textBox = editOrder["cname"];
  textBox["Click"](17, 11);
  textBox["SetText"]("Bender Rodriguez");
  editOrder["OKButton"]["ClickButton"]();
}

The recorded tests can be modified and enhanced in a number of ways to create more flexible and efficient tests. For example, you can:

  • Add new operations, reorder operations and modify their parameters.

  • Delete or disable unneeded operations (for example, superfluous recorded operations).

  • Insert checkpoints for verifying objects and values in the tested application.

  • Create data-driven tests that run multiple test iterations using different sets of data.

Refer to the following topics to learn more about creating and enhancing tests:

Task See topic…
Creating tests using recording Recording Tests
Creating tests manually Keyword Testing and Scripting
Simulating user actions Working With Application Objects and Controls
Running tests Running Tests
Launching applications automatically at the beginning of the test run Launch Web Browsers and
About Tested Applications
Creating checkpoints for verifying application behavior and state Checkpoints
Running multiple test iterations using data from an external file Data-Driven Testing

About Test Types

There are two major test formats in TestComplete:

  • Keyword tests - visually configured tests with grid-based editing interface. Best suited for novice users and those without programming knowledge.

  • Scripts - code written in one of the supported scripting languages. May be better suited for advanced users.

You select the test type when creating a test and cannot change it later. However, you can mix keyword tests and scripts within the same test project and call them from each other.

TestComplete also includes additional test types, such as low-level procedures, unit tests, and so on. You can use them to address specific testing needs. However, most automation is typically done using keyword tests and scripts.

About Silverlight Object Identification and Name Mapping

Each object in an application has a number of properties, such as its location, text, type and so on. Some object properties are persistent and unchanging, and therefore can be used to locate objects in applications and differentiate among various objects.

When you record a test, TestComplete captures all windows and controls that you interacted with during the recording session and adds them to the Name Mapping project item (also known as the object repository or GUI map). For each captured object, TestComplete does the following:

  • Selects a set of properties and values that uniquely identify the object in the application and saves them to Name Mapping as the object identification criteria. These properties will be used for locating the object during subsequent test recording, editing and run sessions.

  • Generates an alias (name) that will be used to reference this object in tests. By default, TestComplete generates aliases based on object names defined in the application by developers.

  • Automatically captures and adds images of the mapped objects to the Name Mapping repository. This helps you understand which window or control one or another mapped object matches.

The following image shows sample Name Mapping for a Silverlight application:

Sample Name Mapping for a Silverlight application

Here, the NewButton object is identified only by one property - SlObjectName. This property specifies the object name as it is defined by the application developers in the application’s source code. However, Silverlight application objects can also be located by other properties, such as their class name, text and so on -- whatever best identifies a specific object.

If needed, you can modify the default Name Mapping generated by TestComplete. For example, you can:

For more information, see Name Mapping.

Keep in mind that the object hierarchy in Name Mapping mirrors the object hierarchy in the tested application. When locating an object, TestComplete takes into account its entire parent hierarchy. If any object in the parent hierarchy cannot be found using the specified property values, the target object cannot be located as well. That is why it is important to select unique and unchanging properties for object identification.

About Support for Silverlight Controls

TestComplete includes a number of special features for testing frequently used standard and third-party Silverlight controls. For detailed information on this, see Support for Silverlight Applications' Controls.

Using Native Silverlight Methods and Properties in Testing

TestComplete exposes visual objects of an in-browser Silverlight application, as well as its internal objects, and provides scripting access to their public properties, fields and methods. See Accessing Native Properties and Methods of Silverlight Objects.

Besides, TestComplete can access namespaces and their classes defined in the application’s assemblies and call the constructors and static members of these classes. For detailed information on how to address exposed objects and their properties and methods from your tests, see Addressing Objects of In-Browser Silverlight Applications

Details

Viewing Object Properties and Methods

To see what operations (methods) are available for objects in your tested Silverlight application, as well as the object properties and their values, you can use the Object Browser or Object Spy. The available properties and methods include those provided by TestComplete, as well as native object properties and methods defined by the developers in the application’s source code.

You can view the object properties and methods both at design time and at run time when the test is paused.

For more information on using the Object Browser, see Object Browser and Exploring Applications.

Samples

TestComplete includes a sample project with Silverlight application tests:

<TestComplete Samples>\Web\Orders\Silverlight

Note: If you do not have the sample, download the TestComplete Samples installation package from the https://support.smartbear.com/testcomplete/downloads/samples/ page of our website and run it.

These tests work with the Orders sample application on our web site:

secure.smartbearsoftware.com/samples/testcomplete15/silverlight/orders.html

Where to Go Next

For more information about automating tests with TestComplete, refer to the following sections:

See Also

Testing Silverlight Applications

Highlight search results