Wednesday, February 25, 2009

Acceptance Testing Silverlight with white

I've used White to acceptance test WPF applications a few times so was pleased to discover it just works with Silverlight. It seems that IE passes the usability api calls into the contained Silverlight app so to an outside caller the app just looks like extra controls within IE. There were a few things I had to make sure were in place though 1. You need to make sure you start IE in a way White can 'find', so if you just pass the URL as the executable name IE (or your default browser) will start but White will not then be able to find that application and window. Obviously you'll need to alter the values to match your install and set up. const string internetExplorer = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE"; const string url = "http://localhost:1138/"; const string windowTitle = "silverlightApp - Microsoft Internet Explorer"; var ie = new ProcessStartInfo(internetExplorer, url); var application = Core.Application.Launch(ie); var window = application.GetWindow(windowTitle, Core.Factory.InitializeOption.NoCache); 2. Make sure you set the automation name property. <TextBox Name="textBox1" Text="some text" AutomationProperties.Name="textbox"/> 3. Use the same Name when you try to find the control. var textBox = window.Get("textbox"); That is it. You'll need to make sure the names you use don't clash with the names of the IE controls, I'd suggest using GUI Spy for that but I've not been able to find a working link to download that tool for about 6 months now. I'm using IE version 6.0 and Silverlight 2. I've not tried this with any other browsers.

2 comments:

Sai Venkatakrishnan said...

Good use of White. But for cross browser stuff or a simpler way of doing this, we have already done silverlight extension for Selenium. :)

Check this out http://code.google.com/p/silverlight-selenium/

GarethD said...

It's actually AutomationProperties.AutomationId

not Name