27. June 2012 08:34
Silverlight certainly isn’t receiving any love at the moment from Microsoft now that the new and shiny WinRT has been announced, however there are still lots of sites and applications built and being built with silverlight. If you look at the list of supported configurations for Coded UI tests you won’t see Silverlight 5 on there (although it kind-of works, like Silverlight 4) there is no plans for adding Silverlight 5 support in Visual Studio 2012. Fortunately, or perhaps because of a few accidents of history, it is possible to test Silverlight 5 UI with Selenium, and once set up the result might actually be superior to the UI automation provided by coded UI. Unfortunately the set-up was a little tricky (hence this blog post) but once you understand the mechanism for the communication it all falls into place pretty nicely. Firstly some context.
So at this stage we have something that looks like this:
On the client one big advantage is you can use the visual tree to ‘find’ UI elements and read their properties (useful for the verification part of tests). This is often an issue in other UI Test Frameworks that sit on top of MSAA or UIA – accessibility attributes need to be set so that automation tools can find the elements, and WPF and silverlight do strange things with some UI Elements like textblocks and the like inside data templates, which make them opaque to accessibility (and UI Automation tools). This approach neatly side-steps this issue. If it is in the visual tree then your ‘helper’ classes can get to it, and you can test it.