PageRenderTime 29ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/V2/trunk/Quickstarts/UI Composition/UIComposition.Tests.AcceptanceTest/UIComposition.Tests.AcceptanceTest/TestEntities/Assertion/UICompositionAssertion.cs

#
C# | 254 lines | 174 code | 46 blank | 34 comment | 0 complexity | 09c19e45d4703d75956082ce36b5ca57 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using AcceptanceTestLibrary.Common;
  22. using Core.UIItems;
  23. using UIComposition.Tests.AcceptanceTest.TestInfrastructure;
  24. using Core.UIItems.TabItems;
  25. using Microsoft.VisualStudio.TestTools.UnitTesting;
  26. using Core.UIItems.Finders;
  27. using AcceptanceTestLibrary.Common.Desktop;
  28. using UIComposition.Tests.AcceptanceTest.TestEntities.Page;
  29. using AcceptanceTestLibrary.ApplicationHelper;
  30. using System.Windows.Automation;
  31. using System.Drawing;
  32. using System.Threading;
  33. using System.Windows.Automation.Peers;
  34. using System.Windows.Automation.Text;
  35. namespace UIComposition.Tests.AcceptanceTest.TestEntities.Assertion
  36. {
  37. public static class UICompositionAssertion<TApp>
  38. where TApp : AppLauncherBase, new()
  39. {
  40. #region Desktop Assertion
  41. private static Tab empDetailsTab;
  42. public static void AssertEmployeeSelection()
  43. {
  44. //select first row (employee)
  45. UICompositionPage<WpfAppLauncher>.EmployeesList.SelectEmployee(0);
  46. //validate details view
  47. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  48. Assert.IsNotNull(empDetailsTab, TestDataInfrastructure.GetTestInputData("EmpDetailsTabNotFound"));
  49. //validate tab has three tab items, and their names are "General", "Location" and "Current Projects"
  50. Assert.AreEqual(3, empDetailsTab.Pages.Count, TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesCount"));
  51. Assert.IsTrue(
  52. (empDetailsTab.Pages[0].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabGeneral")) &&
  53. empDetailsTab.Pages[1].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabLocation")) &&
  54. empDetailsTab.Pages[2].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabCurrentProjects"))),
  55. TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesIncorrect"));
  56. //validate controls in each of the tabs
  57. ValidateGeneralTabControls();
  58. ValidateLocationTabControls();
  59. ValidateCurrentProjectsTabControls();
  60. }
  61. public static void AssertEmployeeGeneralData()
  62. {
  63. //select employee by name
  64. UICompositionPage<WpfAppLauncher>.EmployeesList.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  65. Employee emp = GetEmployeeId();
  66. ValidateEmployeeDetailsGeneralTabData(emp);
  67. }
  68. public static void AssertEmployeeLocationData()
  69. {
  70. UICompositionPage<WpfAppLauncher>.EmployeesList.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  71. ValidateEmployeeDetailsLocationTabData();
  72. }
  73. public static void AssertEmployeeProjectsData()
  74. {
  75. UICompositionPage<WpfAppLauncher>.EmployeesList.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  76. ValidateEmployeeDetailsCurrentProjectsTabData();
  77. }
  78. #endregion
  79. #region SilverLight Assertion
  80. public static void AssertSilverLightEmployeeSelection()
  81. {
  82. AutomationElement employeesListGrid = UICompositionPage<TApp>.EmployeesListGrid;
  83. Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)Math.Floor(employeesListGrid.Current.BoundingRectangle.X + 75), (int)Math.Floor(employeesListGrid.Current.BoundingRectangle.Y + 55));
  84. Core.InputDevices.Mouse.Instance.Click();
  85. Thread.Sleep(5000);
  86. Assert.IsNotNull(employeesListGrid, "Could not find employees list grid");
  87. }
  88. public static void AssertSilverLightEmployeeGeneralData()
  89. {
  90. AutomationElement employeesListGrid = UICompositionPage<TApp>.EmployeesListGrid;
  91. Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)Math.Floor(employeesListGrid.Current.BoundingRectangle.X + 75), (int)Math.Floor(employeesListGrid.Current.BoundingRectangle.Y + 55));
  92. Core.InputDevices.Mouse.Instance.Click();
  93. Thread.Sleep(5000);
  94. AutomationElement firstName = UICompositionPage<TApp>.SilverLightFirstNameTextBox;
  95. AutomationElement lastName = UICompositionPage<TApp>.SilverLightLastNameTextBox;
  96. AutomationElement phoneText = UICompositionPage<TApp>.SilverLightPhoneTextBox;
  97. AutomationElement emailText = UICompositionPage<TApp>.SilverLightEmailTextBox;
  98. Assert.IsNotNull(firstName, "Could not find first name text box");
  99. Assert.IsNotNull(lastName, "Could not find last name text box");
  100. Assert.IsNotNull(phoneText, "Could not find phone text box");
  101. Assert.IsNotNull(emailText, "Could not find email text box");
  102. Employee emp = GetEmployeeId2();
  103. Assert.AreEqual(firstName.Current.Name, emp.FirstName);
  104. Assert.AreEqual(lastName.Current.Name, emp.LastName);
  105. Assert.AreEqual(phoneText.Current.Name, emp.Phone);
  106. Assert.AreEqual(emailText.Current.Name, emp.Email);
  107. }
  108. public static void AssertSilverLightEmployeeCurrentProjects()
  109. {
  110. AutomationElement employeeTab = UICompositionPage<TApp>.EmployeeDetailsTabControl;
  111. // Select Current Projects Tab
  112. AutomationElement aeTabPage = employeeTab.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Current Projects"));
  113. Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)Math.Floor(aeTabPage.Current.BoundingRectangle.X), (int)Math.Floor(aeTabPage.Current.BoundingRectangle.Y));
  114. Core.InputDevices.Mouse.Instance.Click();
  115. //Check if the current projects grid is loaded.
  116. AutomationElement currentProjectsGrid = UICompositionPage<TApp>.SilverLightProjectsGrid;
  117. GridPattern projectPattern = currentProjectsGrid.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
  118. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("ProjectsRowCount"), projectPattern.Current.RowCount.ToString());
  119. }
  120. #endregion
  121. #region Private Helper methods
  122. private static void ValidateGeneralTabControls()
  123. {
  124. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  125. empDetailsTab.Pages[0].Select();
  126. //check all Labels (TextBlocks)
  127. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.FirstNameLabel);
  128. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.LastNameLabel);
  129. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.PhoneLabel);
  130. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.EmailLabel);
  131. //check all Textboxes
  132. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.FirstNameTextbox);
  133. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.LastNameTextBox);
  134. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.PhoneTextBox);
  135. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.EmailTextBox);
  136. }
  137. private static void ValidateLocationTabControls()
  138. {
  139. //Acceptance Tests for UI Composition do not validate the location of the selected Employee
  140. //in the Live Search Maps displayed in a HTML frame control.This method is the right place
  141. //to do any assertions for Employee Location displayed in HTML frame control.
  142. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  143. empDetailsTab.Pages[1].Select();
  144. }
  145. private static void ValidateCurrentProjectsTabControls()
  146. {
  147. //select the "Current Projects" tab
  148. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  149. empDetailsTab.Pages[2].Select();
  150. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.ProjectsLabel);
  151. Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.ProjectsList);
  152. }
  153. private static void ValidateEmployeeDetailsGeneralTabData(Employee emp)
  154. {
  155. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  156. Thread.Sleep(2000);
  157. empDetailsTab.Pages[0].Select();
  158. Thread.Sleep(2000);
  159. Assert.AreEqual(UICompositionPage<WpfAppLauncher>.FirstNameTextbox.Text, emp.FirstName);
  160. Assert.AreEqual(UICompositionPage<WpfAppLauncher>.LastNameTextBox.Text, emp.LastName);
  161. Assert.AreEqual(UICompositionPage<WpfAppLauncher>.PhoneTextBox.Text, emp.Phone);
  162. Assert.AreEqual(UICompositionPage<WpfAppLauncher>.EmailTextBox.Text, emp.Email);
  163. }
  164. private static void ValidateEmployeeDetailsLocationTabData()
  165. {
  166. //Acceptance Tests for UI Composition do not validate the location of the selected Employee
  167. //in the Live Search Maps displayed in a HTML frame control.This method is the right place
  168. //to do any assertions for Employee Location displayed in HTML frame control.
  169. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  170. empDetailsTab.Pages[1].Select();
  171. }
  172. private static void ValidateEmployeeDetailsCurrentProjectsTabData()
  173. {
  174. empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
  175. Thread.Sleep(2000);
  176. empDetailsTab.Pages[2].Select();
  177. Thread.Sleep(2000);
  178. ListView projectsList = UICompositionPage<WpfAppLauncher>.ProjectsList;
  179. //check if the list has two columns
  180. Assert.AreEqual(2, projectsList.Header.Columns.Count);
  181. //check if the list has two rows
  182. Assert.AreEqual(2, projectsList.Rows.Count);
  183. }
  184. private static Employee GetEmployeeId()
  185. {
  186. Employee emp = new Employee(1)
  187. {
  188. FirstName = TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"),
  189. LastName = TestDataInfrastructure.GetTestInputData("Emp_1_LastName"),
  190. Phone = TestDataInfrastructure.GetTestInputData("Emp_1_Phone"),
  191. Email = TestDataInfrastructure.GetTestInputData("Emp_1_Email")
  192. };
  193. return emp;
  194. }
  195. private static Employee GetEmployeeId2()
  196. {
  197. Employee emp = new Employee(1)
  198. {
  199. FirstName = TestDataInfrastructure.GetTestInputData("Emp_2_FirstName"),
  200. LastName = TestDataInfrastructure.GetTestInputData("Emp_2_LastName"),
  201. Phone = TestDataInfrastructure.GetTestInputData("Emp_2_Phone"),
  202. Email = TestDataInfrastructure.GetTestInputData("Emp_2_Email")
  203. };
  204. return emp;
  205. }
  206. #endregion
  207. }
  208. }