PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/Quickstarts/UIComposition/UIComposition.Tests.AcceptanceTest/UIComposition.Tests.AcceptanceTest/TestEntities/Assertion/UICompositionAssertion.cs

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