Getting Started with ComponentOne Studio Silverlight Edition
Automated UI Testing using C1.Silverlight.Automation.dll

Let's add unit testing for the OutlookBarSamples from Silverlight Edition samples as an example.

Note: ComponentOne samples are installed, by default, in the ComponentOne Samples folder in  Documents\ComponentOne Samples\Silverlight

This first step shows what we see without using the C1.Silverlight.Automation.dll.

  1. Start the OutlookBarSamples without any modifications and explore the automation tree of the application using UI Spy or a similar tool.

    The tree looks like an unorganized list of images and buttons. It does not seem to be useful for writing tests.

     

     

  2. Add a reference to the C1.Silverlight.Automation.dll to your project.

     

     

  3. Start the application and explore the automation tree:

     

     

    Now it looks like something we can work with.

  4. Create a test project and add to the solution.

     

     

  5. Set up the solution:
    • Set OutlookBarSamples2010Web as the startup project.
    • Specify the project properties an in the following example:

       

  6. Add a CodedUITest to the test project.
  7. Write some unit tests. Find automation elements and use their patterns.

            [TestMethod]

    C#
    Copy Code
     public void OutlookBarCollapseExpand()
            {
                BrowserWindow.CurrentBrowser = "IE";
                // Run Browser
                BrowserWindow win = BrowserWindow.Launch("about:blank");
                System.Diagnostics.Process process = SearchIEProcess("Blank Page");
                try
                {
    
                    win.NavigateToUrl(new Uri("http://localhost:7777"));
                    // Wait some time to complete
                    System.Threading.Thread.Sleep(5000);
                    AutomationElement mainElement = System.Windows.Automation.AutomationElement.FromHandle(process.MainWindowHandle);
    
                    AutomationElement outlookBar = mainElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "C1OutlookBar"));
                    Assert.IsNotNull(outlookBar, "Cannot find control.");
    
                    object pattern = null;
                    outlookBar.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern);
                    Assert.IsNotNull(pattern, "Cannot find ExpandCollapsePattern.");
                    ExpandCollapsePattern expandCollapsePattern = (ExpandCollapsePattern)pattern;
    
                    bool collapsed = expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed;
                    Assert.IsFalse(collapsed, "OutlookBar should be expanded on start");
    
                    expandCollapsePattern.Collapse();
                    collapsed = expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed;
                    Assert.IsTrue(collapsed, "OutlookBar should be collapsed now");
    
                    var items = mainElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "C1OutlookItem"));
                    Assert.AreEqual(5, items.Count, "5 OutlookItems expected");
    
                    System.Threading.Thread.Sleep(2000);
                }
                finally
                {
                    // Close browser
                    process.CloseMainWindow();
                }
            }
    

           

  8. Run the tests.

     

     

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback