This is RIATest 5 documentation. If you are looking for RIATest 6 documentation click here.
Cogitek RIATest 5 Documentation Copyright © Cogitek Inc.

Testing Silverlight applications using RIATest

This article describes how to test Silverlight applications using RIATest. It is assumed that you have RIATest 4.2 or later and your Silverlight application is compiled and ready to be opened as an HTML file or URL in a browser. The sample Silverlight application and RIATest project can be downloaded here.

Creating a RIATest project

To get started with the test, firstly create an empty project in RIATest using the File|New Project menu command. Specify the project name and folder and click OK.

New Project

Now select Project|Options from the menu. In the Project Options window, enable the following 3 options:

Then select Loading Type "In browser application".

If your Silverlight application is located on a web server, type the full URL of the HTML file that loads the application in the "Application URL or File" box. If the application is located on your hard drive click the Browse button and point to the Silverlight application HTML file.

Project Options

Click OK to close the Project Options window.

Everything is now set up ready to launch the Silverlight application from RIATest. Click the green Launch button from the toolbar.

The browser opens and the Silverlight application is loaded into the browser.

Creating a test script

To create a test script, first select the Project|Add New Script menu command and type "FirstTest" to create a new test script file and add it to the project.

Copy the following 2 lines to your script file:

var browserWin = getLastBrowser().getWindow();
var app = browserWin.getDescendant(SysWindow("Silverlight Control"));

The first line gets the locator of the browser window that was last opened by RIATest. The second line finds a Silverlight control within the descendants of the window.

The "app" variable will hold the top-level control that corresponds to the Silverlight application. We will use this variable in the script to locate and act on the controls contained in the application.

Now we are going to use the dynamic code completion capability that was introduced in RIATest 4.2 to see easily what controls are available in the application and write script code that interacts with the controls.

Dynamic code completion is activated in RIATest when the script is being debugged and you request code completion on a variable that has been assigned a value by the script.

First begin debugging the application and step over the 2 lines that you have added to the script. The execution will stop on the last character of the last line. (Note: if you attempt to perform one more "Step Over" action in the debugger then the execution will finish, so make sure you do not do it at this time to keep debugging mode active.)

Now hit Enter and type the following on a new line:

var tabs = app->

A code completion popup should appear showing the available controls in the application. We can see that there is just one child control available: SysTab({AutomationId:"mainTabs"}).

Code Completion

Hit Enter to accept the suggested completion. Now you can continue and write some more script code. Type the following:

var tabs =  app->SysTab({AutomationId:"mainTabs"});
var simpleTab = tabs->SysTabItem("Simple");

simpleTab->SysRadioButton("Button A")=>Select();

Notice that as soon as you type the hyphen-arrow symbol (->) then code completion kicks in and offers the available child objects. Similarly when you type the equals-arrow symbol (=>) code completion offers the available functions and properties.

Running tests and checking results

So we have successfully created a project and set up the first test. We will now run the test to see what happens.

Click the Run button. A browser window is opened, the Silverlight application is loaded and the actions that you created in the test script are simulated on the application. Wait until the test is finished and the browser window closes.

You can see the results of the test in the RIATest IDE. You can see the duration of the test and that the overall result is 'ALL OK'. Then there are the statistics for startup and shutdown and by scripts. We only have one test script in our project. We see that 3 actions and 1 verification were performed.

Exec Results

Now click the script name to see the execution details for the script. You can see the actions and the one verification that we had. Clicking on a line number will show the actual script line that resulted in this message.

Exec Result Details

Now let's see how RIATest reports errors. Change the verifyEqual statement to check ToggleState against a different value:


Run the tests again and see how RIATest catches the problem in the application.

Click the Run button. The test starts running and the RIATest IDE is shown. You can see that the execution is suspended on the verifyEqual statement and an error message is displayed. The message says that the ToggleState property does not match the expected value:

Verify Fail

Let's continue execution to the end. Click the Run button once again. The results of the test now tell us that errors were found:

Exec Results Fail

Scroll down to see which line generated an error.

That's it. You have successfully created a simple Silverlight testing project, created a test, run the test and checked the results!


Found a typo? Have a suggestion? Please submit your request here.