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

15 thoughts on “Silvernium ~ Selenium for Silverlight Applications

  1. November 7, 2012 at 2:36 am

    New and interesting! Keep up the good work Manoj!

    1. November 7, 2012 at 8:59 am

      Thank you Kadhar

  2. DVD movies
    November 8, 2012 at 2:13 pm

    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.

    1. November 8, 2012 at 2:32 pm

      I am glad it helps you. Keep visiting.


  3. Sreevatsa
    November 8, 2012 at 7:42 pm

    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.

    1. November 8, 2012 at 8:03 pm

      Yes, it is possible through the Selenium RC API.
      Please refer

      You will need to follow those steps to do automation on Flex apps. As Flex is different from other applications we cannot just go directly and automate but just some modification needs to be done on the code base of the applications through developers.

  4. blog
    November 14, 2012 at 3:38 am

    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
    November 15, 2012 at 12:26 am

    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
    November 20, 2012 at 10:22 am

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

    1. November 20, 2012 at 10:34 am

      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
    December 17, 2012 at 9:43 pm

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

    1. January 21, 2013 at 3:39 pm

      I am not sure on that.

  8. Hameed
    August 2, 2013 at 7:47 am

    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…

  9. subhan
    January 20, 2014 at 11:00 am

    Hi Manoj,
    I’m trying to automate my application which is developed with different tools like kendo, telerik and silverlight. when it comes to silverlight objects its like blank, not able to do anything. I’m using Selenium webdriver to automate this scenario. Is there any workaround to work with silverlight objects with selenuim webdriver. If so, please let me know or atleast give some hints.

  10. sid
    April 22, 2014 at 7:14 am

    From this post I see that Selenium RC is used.
    But can we automate silverlight application using WebDriver?

Leave a Reply

Your email address will not be published. Required fields are marked *