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:

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

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

13 Responses to “Silvernium ~ Selenium for Silverlight Applications”
  1. kadharmr says:

    New and interesting! Keep up the good work Manoj!

  2. DVD movies says:

    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.

  3. Sreevatsa says:

    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.

  4. blog says:

    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.

  5. Anonymous says:

    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.

  6. Pratik Dholakia says:

    Is it possible to automate any silverlight application using java code in eclipse?

    • It is possible and the post above conveys the same. Provided you should do the same changes as mentioned the post to your application code base (adding SCRIPTABLE keyword)

  7. Massimo Forno says:

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

  8. Hameed says:

    I am trying to automate my application which is developed in silvernium. I tried in eclipse(using Java). But i am not able to identify the objects. Can anyone help me in this…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: