ArtOfTest

Skip Navigation Links

Feed from our Blogs

Intro to Silverlight Automation

Silverlight automation has been our main focus since the release of Automation Design Canvas 1.1 earlier this year. Lots of customers ask us when Design Canvas will support Silverlight recording and I want to assure everyone that we are actively working on it. It is our #1 priority here at ArtOfTest. We do hope to preview our recording for Silverlight (which I'm sure is going to impress many) soon. Silverlight recording will be part of Automation Design Canvas 2.0 when its released.

As for this blog post, I'm going to dedicate it to talk more about WebAii 2.0 framework and its impressive support for automating Silverlight applications. WebAii 2.0 is going to be the framework on top of which Automation Design Canvas 2.0 and Silverlight recording/execution will be built.

In this post, I would like to discuss the following:

  1. Why WebAii 2.0 sticks out as the clear choice when looking for Silverlight automation solutions.
  2. Go over a simple example that is geared towards users that are new or just getting started.

Next post I will go over:

  1. Talk a bit about some of the rich and advanced features for Silverlight automation in WebAii 2.0.
  2. Demonstrate a more complex automation scenario that shows-off some of these advanced capabilities.

So, let's get started....

Why choose WebAii for Silverlight automation?

Well, there are tons of reasons why. I'm going to try to summarize them in the following points.

  1. WebAii plugs-in directly into Silverlight applications it automates. It has access to every single element/object in the entire Silverlight application. This allows us to expose a rich feature set with very little limitations.
  2. WebAii is NOT limited to what UIAutomation interfaces expose on each object. Beside the ability to perform basic automation actions like clicking, moving and setting text, WebAii gives you access to all properties including complex properties on UI elements such as brushes, borders and even transform matrices..etc. It allows you to get and set most of these properties which is very critical when it comes to test verifications and test synchronizations. For example, you can wait until a certain animation in Silverlight has changed a certain brush to a certain color.
  3. WebAii has a complete UI object model under ArtOfTest.WebAii.Silverlight.UI namespace that mimics the complete list of UI XAML elements that Silverlight ships with including the extended controls that ship with Silverlight. This allows you to access everything in your application as if you are sitting inside the Silverlight application and using the same object model.
  4. WebAii comes with an extensibility model that allows you to extend its current support. You want to access a custom property on a custom control? No problem, with few lines of code, you can achieve that. The best part is that the application being tested (the production application) does not need to be touched at all. There are no extra UIAutomation interfaces to implement or objects to add. Less code churn is always a good thing especially for production applications.
  5. A one stop shop for everything Web. WebAii 2.0 includes rich support for Html/Ajax automation along side Silverlight automation: One framework and one consistent API that allows you to automate all your web application needs regardless of the technology you are using!
  6. WebAii enables real user simulation with the User.<action> methods in addition to direct API access. These methods move the mouse just like the user, type just like the user and even offer hotspot detection just like a user would do. This real user simulation is critical when rich UI scenarios are needed for automation like hover overs, drags..etc.

 

Getting Started with a simple example

First, make sure to download and install WebAii 2.0 Beta from our website here: http://www.artoftest.com/products/downloads.aspx. If you already have WebAii 1.1 or Automation Design Canvas 1.1 on your machine, no worries. WebAii 2.0 runs Side by Side with 1.1. There is only one known issue currently using Firefox. You need to disable the 1.1 extension in Firefox's add-on dialog (Tools->Add-ons) to allow the 2.0 extension to work. You can later on re-enable it when you want to switch back to 1.1.

Now that you have the framework installed, you will notice that it comes with a sample VS Solution that contains several samples that demos the 2.0 feature set including a Silverlight sample test. The installer should have placed a short-cut in your start menu. Click Start->All Programs->ArtOfTest Inc.->WebAii 2.0 Beta and then click on "Open WebAii 2…” which should launch Visual Studio and load the sample solution.

The sample Silverlight test simply automates a simple application located here:

image

 

The test basically performs the following actions:

1. Launch the browser and Navigate to the URL above.

2. Connect to the Silverlight application on that page.

3. Set the text in the textbox to: ArtOfTest.

4. Select a date.

5. Click the ‘OK’ button.

6. Validate the message “Hi ArtOfTest”.

 So let’s automate the above scenario using WebAii.

1. Launch a new browser instance and navigate to the URL above. This is basic WebAii stuff.
 1: // Launch a new browser instance.
 2: Manager.LaunchNewBrowser();
 3:  
 4: // Navigate to the page.
 5: ActiveBrowser.NavigateTo("http://www.artoftest.com/samples/SampleApplication.html");
2.  Connect to the Silverlight application on the page.
 1: SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
 2: Assert.IsNotNull(app);

Few things to note here:

a. As soon as you include the ArtOfTest.WebAii.Silverlight namespace. An extension method “SilverlightApps” is added to the Browser object. This method allows you to access all Silverlight applications on the page.

b. WebAii allows you to access and automate any of your Silverlight apps/islands that are on your page simultaneously.

c. The accessor on the SilverlightApps collection method, internally calls SilverlightApp.Connect which basically activates a connection between that SilverlightApp instance and the live instance in your browser.

At this point we have access to all of the UI element in the Silverlight application.

3. Set the text for the Name to ArtOfTest.
 1: TextBox name1 = app.Find.ByName<TextBox>("name1");
 2: Assert.IsNotNull(name1);
 3: name1.Text = "ArtOfTest";

As you can see, this is where the power of WebAii starts to show. You will notice that there is a Find object  on the app that supports all the common ways customers might want to find an element inside the Silverlight application. In this case we are using the Find.ByName. Other supported search routines include: Find.ByText, Find.ByAutomationId, Find.ByType.

The object returned from the Find call is a strongly-typed TextBox object that resembles the System.Windows.Controls.TextBox object in Silverlight. It contains a similar object model which enables you to manipulate it directly. For example, line three above sets the text to “ArtOfTest”.

4. Select a date from the calendar.

You might think that this is going to be a pretty complex operation to implement. But it is not given the fact that WebAii supports all the native rich controls that come out of the box with Silverlight. Here is the code to select a date:

 1: Calendar cal1 = app.Find.ByName<Calendar>("cal1");
 2: Assert.IsNotNull(cal1);
 3: cal1.SelectedDate = DateTime.Now;

That is it. Using the rich object model provided you are able to access a strongly-typed Calendar object and set the date on it. The code is concise, intuitive and easy to read.

5. Click the OK button.

Again, this is pretty simply.

 1: Button ok = app.Find.ByName<Button>("okButton");
 2: Assert.IsNotNull(ok);
 3: ok.User.Click();

Note, here the “User.Click()”. When using any method off the User.xx class, you are really simulating real user interaction with the application. Inside that call, WebAii has determined exactly where the center of that button is on the screen, moved the mouse to it and clicked the button.

6. Now, let’s validate that the button was clicked and that the text is exactly how we want it.
 1: TextBlock message1 = app.Find.ByName<TextBlock>("message1");
 2: Assert.IsNotNull(message1);
 3: Assert.IsTrue(message1.Text.StartsWith("Hi ArtOfTest"));

Again, we are using the strongly typed objects of WebAii to help us easily craft and build test automation.

Summary

As you can see, lots of thought and innovation went into the design of Silverlight automation to make it as simple to use but also as rich as possible. What we discussed above is simply the tip of the iceberg. In the next blog, we will go over some of the more advanced scenarios in Silverlight that really show-off the power of the framework we have built! The best part of all this, It is FREE!!

Our preliminary documentation for WebAii 2.0 Beta can be found here, including its API Reference

ArtOfTest, Inc. Team.

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

 Copyright 2009 © ArtOfTest, Inc. All rights reserved  |   Privacy Policy  |  Terms of Use 

Have a question for ArtOfTest?
First Name
Last Name
Company
Email
Question:

701 Brazos Street
Suite 320
Austin, TX 78701
Tel: (512) 535-2428
Fax: (512) 722-7748
contact@artoftest.com