The 2010 Q1 Service Pack adds an important solution to a common problem in automating Silverlight applications – ChildWindow and Popups automation support.

The Problem

Automating popups has always been a challenge for the UI automation tools. In Silverlight it’s even more complicated because the popup controls are not part of the SL Visual Tree. WebUI Test Studio could not access those elements in the visual tree and we couldn’t automate them.

The Solution

With the 2010 Q1 SP release we add a new assembly (Telerik.WebUI.PopupTracker available in the installation Bin folder) to serve as popup tracker. Those who want to automate ChildWindows or Popups should include this assembly in their application’s references and call it in one of the following ways:

When subclassing Popup or ChildWindow, the subclass can call PopupTracker.Track() in its constructor.

 

public partial class PopupWindow : ChildWindow
{
    public PopupWindow()
    {
        Telerik.WebUI.PopupTracker.Track(this);

        InitializeComponent();
    }
}

When creating a Popup or ChildWindow programmatically, call PopupTracker.Track() after creating the object.

 

Popup myPopup = new Popup();
Telerik.WebUI.PopupTracker.Track(myPopup);



WebAii Framework users who want to automate ChildWindows or Popups should use the new SilverlightApp method RefreshVisualTrees() instead of calling app.VisualTree.Refresh()RefreshVisualTrees() will retrieve visual trees for all open Popups and ChildWindows as well as refreshing the main application visual tree.  App.VisualTree only accesses the main visual tree.

Popup and ChildWindow visual trees are available via a new property SilverlightApp.Popups.  This property contains a list of VisualTreeHosts, each of which wraps a visual tree, available as its VisualTree property.

Example

I’m using this code example of adding ChildWindow in a Silverlight sample application. The application creates a “PopupWindow” control deriving from ChildWindow. The control serves as popup confirmation with OK and Cancel buttons.

<controls:ChildWindow x:Class="SilverlightApplication1.PopupWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Width="200" Height="150" Title="PopupWindow"> <Grid x:Name="LayoutRoot" Margin="2"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock x:Name="Message" Text="" TextWrapping="Wrap"/> <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" /> <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" /> </Grid> </controls:ChildWindow>



The PopupWindow is instantiated in the MainPage constructor:

 

 public partial class MainPage : UserControl
    {
        private PopupWindow popupWindow;

        public MainPage()
        {
            InitializeComponent();
            popupWindow = new PopupWindow();
            popupWindow.Closed += new EventHandler(PopupWindow_Closed);
        }
    
        ...
    }



Now let’s add a reference to the PopupTracker assembly and call PopupTracker.Track() accordingly:

 public MainPage()
    {
        InitializeComponent();
        popupWindow = new PopupWindow();
        popupWindow.Closed += new EventHandler(PopupWindow_Closed);

        PopupTracker.Track(popupWindow);
    }



Finally WebUI Test Studio can automatically detect the popup and record any actions/verifications over that as expected:

ChildWindow

Have you upgraded to the SP release? We will be happy to get your feedback about the Automated Testing Tools new additions and improvements!

 

Yours,

-Konstantin


Related Posts

Comments

Comments are disabled in preview mode.