Getting Started with Silverlight Edition Overview > Silverlight Automation Overview > 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.
The tree looks like an unorganized list of images and buttons. It does not seem to be useful for writing tests.
Now it looks like something we can work with.
[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(); } } |