Silvernium ~ Selenium for Silverlight Applications

SilverLight Application Automation

Selenium Support for SilverLight Applications

The Silverlight is a relatively new client side technology released by Microsoft .To automate the Silverlight application using Selenium Open source is not possible directly. But in the open source market we can use the Silvernium component to automate the Silverlight application with the selenium RC Background
The Silvernium component

The Silvernium is a Selenium RC Client driver extension for helping exercise the tests against the Silverlight component and adding Silverlight communication capabilities to the Selenium framework.

From Silvernium Scripter (Client Side):

The Silvernium constructor takes a Selenium instance and the Silverlight object ID and the scriptable key as parameters. An instance of Silvernium is used to invoke the functions on the Silverlight application.
You can invoke functions which were externalized by the Scriptable attribute, as well as the default functions and properties of any Silverlight object(e.g, ,,background, isLoaded,ActualWidth(), etc)

Sample Program:

[sourcecode language=”csharp”]
using NUnit.Framework;
using Selenium;
using ThoughtWorks.Selenium.Silvernium;

namespace IntegrationTests
public class OurApplicationclass
private const string URL = "<Your Silverlight App URI>";
private const string OBJECTID = "";
private const string SCRIPTKEY = "";
private ISelenium selenium;
private Silvernium silvernium;

public void SetUp()
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", URL);
silvernium = new Silvernium(selenium, OBJECTID, SCRIPTKEY);

public void TearDown()
public void TestCase1()
Assert.AreEqual("Application title", selenium.GetTitle());
// verifies default properties in the silverlight object
Assert.AreEqual(640, silvernium.ActualWidth());
Assert.AreEqual(460, silvernium.ActualHeight());

// verifies user defined properties and methods
Assert.AreEqual("5", silvernium.GetPropertyValue("StartingSpeed"));
// content.SilverNibbles.NewGame(‘1’);, returns null
Assert.AreEqual("null", silvernium.Call("NewGame", "1"));

// testing set and get for a user defined property
Assert.AreEqual("5", silvernium.GetPropertyValue("StartingSpeed"));
// setting the property
silvernium.SetPropertyValue("StartingSpeed", "8");
// getting it again
Assert.AreEqual("8", silvernium.GetPropertyValue("StartingSpeed"));
public void TestCase2()
//Actions to perform

From Server side – Selenium RC-Silverlight Integration

(Which is Prerequisites to execute Silvernium components)
Selenium RC uses JavaScript to communicate with the browser. Silverlight Scriptable attribute provides a mechanism to mark the Silverlight application’s classes and functions available for JavaScript calls. Therefore Silverlight-Selenium uses JavaScript as the conduit between Selenium RC and the Silverlight application. With Silverlight Scriptable attribute you can expose specific Silverlight application functions.
Scriptable attribute definition for each class and each event lets Silverlight to know that this class and these events should be accessible from the JavaScript code.

Example: This Silverlight application has three buttons, consists three events – one for each button. They’re created and used exactly like they are in an ordinary C# Windows application

[sourcecode language=”csharp”]
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Browser;

namespace SilverlightJavascript
public partial class Page : Canvas
public event EventHandler ButtonAClicked;
public event EventHandler ButtonBClicked;
public event EventHandler ButtonCClicked;

public void Page_Loaded(object o, EventArgs e)
// Required to initialize variables

WebApplication.Current.RegisterScriptableObject("SilverlightApp", this);

• The [Scriptable] attribute above the definition of the class and each event lets Silverlight know that this class and these events should be accessible from the JavaScript code.
• The RegisterScriptableObject call with this function, telling Silverlight to make this class accessible via scripts by the name “SilverlightApp”. Now whenever I want to use this object in JavaScript, I’ll reference it by the name “SilverlightApp”

With that I hope all the readers might got an idea what exactly Silvernium components comprises and its implementations:)

This is just the Implementation Concept and we really need an Silverlight application to see them working live

17 thoughts on “Silvernium ~ Selenium for Silverlight Applications”

  1. Thank you for sharing superb informations. Your site is very cool. I’m impressed by the details that you抳e on this blog. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched everywhere and just could not come across. What an ideal site.

  2. I have a question regarding Selenium and Flex automation using Selenium Webdriver. Is this possible? If yes, please let me know the steps on how to perform the same.

  3. I wanted to send you the bit of word so as to thank you very much as before relating to the striking information you have shared here. It is simply extremely generous of you to give unhampered all a number of people would’ve marketed as an electronic book to generate some profit on their own, mostly seeing that you could possibly have tried it in the event you desired. Those secrets in addition served to be a fantastic way to realize that other individuals have the identical zeal much like my own to know more with regards to this problem. I am sure there are millions of more pleasurable sessions ahead for people who scan through your blog post.

  4. Thanks so much for giving everyone remarkably memorable chance to read in detail from this web site. It is often so terrific plus full of a good time for me personally and my office mates to search your blog the equivalent of thrice weekly to study the newest stuff you will have. And lastly, I’m so usually pleased considering the eye-popping tactics served by you. Selected 2 areas in this posting are indeed the most impressive I’ve ever had.

  5. Hi,
    is there any way to get the same extension using Webdriver as Selenium RC is considered as deprecated?
    Many thanks in advance,

  6. Hi Manoj,

    I want to automate some Silverlight Related controls in our Application. Using Selenium in C# is it possible. Can you provide some of the examples.


  7. To implement this in Java environment , Do we need any Jar file to import , If yes please let me know…..Any Help would be appreciated.

Leave a Comment