PageRenderTime 29ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms 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//===================================================================================
 33using System;
 34using AcceptanceTestLibrary.Common;
 35using UIComposition.Tests.AcceptanceTest.TestInfrastructure;
 36using Microsoft.VisualStudio.TestTools.UnitTesting;
 37using AcceptanceTestLibrary.Common.Desktop;
 38using UIComposition.Tests.AcceptanceTest.TestEntities.Page;
 39using System.Windows.Automation;
 40using System.Drawing;
 41using System.Threading;
 42using AcceptanceTestLibrary.UIAWrapper;
 43
 44namespace UIComposition.Tests.AcceptanceTest.TestEntities.Assertion
 45{
 46    public static class UICompositionAssertion<TApp>
 47        where TApp : AppLauncherBase, new()
 48    {
 49        //#region Desktop Assertion
 50        //private static AutomationElementCollection empDetailsTab;
 51        ////
 52        //public static void AssertEmployeeSelection()
 53        //{
 54        //    //select first row (employee)
 55        //    AutomationElementCollection employeeList = UICompositionPage<WpfAppLauncher>.EmployeesList;           
 56        //    employeeList[1].SetFocus();
 57        //    employeeList[1].Select();
 58        //    Thread.Sleep(7000);
 59        //    //validate details view
 60        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
 61
 62           
 63        //    Assert.IsNotNull(empDetailsTab, TestDataInfrastructure.GetTestInputData("EmpDetailsTabNotFound"));
 64
 65        //    //validate tab has three tab items, and their names are "General", "Location" and "Current Projects"
 66        //    Assert.AreEqual(3, empDetailsTab.Count, TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesCount"));
 67        //    Assert.AreEqual(empDetailsTab[0].Current.Name.ToString(), TestDataInfrastructure.GetTestInputData("EmpDetailsTabGeneral"));
 68        //    Assert.AreEqual( empDetailsTab[1].Current.Name, TestDataInfrastructure.GetTestInputData("EmpDetailsTabLocation"));
 69        //    Assert.AreEqual(empDetailsTab[2].Current.Name, TestDataInfrastructure.GetTestInputData("EmpDetailsTabCurrentProjects"));
 70        //        ////TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesIncorrect"));
 71
 72        //    //validate controls in each of the tabs
 73        //    ValidateGeneralTabControls();
 74        //    ValidateLocationTabControls();
 75        //    ValidateCurrentProjectsTabControls();
 76        //}
 77
 78        //public static void AssertEmployeeGeneralData()
 79        //{
 80        //    //select employee by name
 81        //    AutomationElementCollection employeeList = UICompositionPage<WpfAppLauncher>.EmployeesList;            
 82        //    employeeList[1].SetFocus();
 83        //    employeeList[1].Select();
 84        //    Thread.Sleep(7000);
 85        //    Employee emp = GetEmployeeId();
 86        //    ValidateEmployeeDetailsGeneralTabData(emp);
 87        //}
 88
 89        //public static void AssertEmployeeLocationData()
 90        //{
 91        //    Thread.Sleep(3000);
 92        //    AutomationElementCollection employeeList = UICompositionPage<WpfAppLauncher>.EmployeesList;           
 93        //    employeeList[1].SetFocus();
 94        //    employeeList[1].Select();
 95        //    Thread.Sleep(7000);
 96        //    ValidateEmployeeDetailsLocationTabData();
 97        //}
 98
 99        //public static void AssertEmployeeProjectsData()
100        //{           
101        //    AutomationElementCollection employeeList = UICompositionPage<WpfAppLauncher>.EmployeesList;           
102        //    employeeList[1].SetFocus();
103        //    employeeList[1].Select();
104        //    Thread.Sleep(7000);
105
106        //    ValidateEmployeeDetailsCurrentProjectsTabData();
107        //}
108        //#endregion
109
110        #region SilverLight Assertion
111        public static void AssertSilverLightEmployeeSelection()
112        {
113            AutomationElement employeesListGrid = UICompositionPage<TApp>.EmployeesListGrid;           
114            Assert.IsNotNull(employeesListGrid, "Could not find employees list view");
115        }
116
117        public static void AssertSilverLightEmployeeGeneralData()
118        {
119            AutomationElement employeesListGrid = UICompositionPage<TApp>.EmployeesListGrid;           
120
121             AutomationElementCollection aeEmployeesList = UICompositionPage<TApp>.EmployeesGridItems;         
122            aeEmployeesList[1].Click();
123            Thread.Sleep(2000);
124
125            for(int count=0; count<aeEmployeesList.Count; count++)
126            {
127                aeEmployeesList[count].Select();
128                Thread.Sleep(2000);
129                
130                AutomationElement firstName = UICompositionPage<TApp>.SilverLightFirstNameTextBox;
131                AutomationElement lastName = UICompositionPage<TApp>.SilverLightLastNameTextBox;
132                AutomationElement phoneText = UICompositionPage<TApp>.SilverLightPhoneTextBox;
133                AutomationElement emailText = UICompositionPage<TApp>.SilverLightEmailTextBox;
134
135                Assert.IsNotNull(firstName, "Could not find first name text box");
136                Assert.IsNotNull(lastName, "Could not find last name text box");
137                Assert.IsNotNull(phoneText, "Could not find phone text box");
138                Assert.IsNotNull(emailText, "Could not find email text box");
139                Employee emp = GetEmployeeId((count+1).ToString());
140                Assert.AreEqual(firstName.Current.Name, emp.FirstName);
141                Assert.AreEqual(lastName.Current.Name, emp.LastName);
142                Assert.AreEqual(phoneText.Current.Name, emp.Phone);
143                Assert.AreEqual(emailText.Current.Name, emp.Email);
144
145            }
146
147        }
148
149        public static void AssertSilverLightEmployeeCurrentProjects()
150        {
151            AutomationElement employeesListGrid = UICompositionPage<TApp>.EmployeesListGrid;
152
153            AutomationElementCollection aeEmployeesList = UICompositionPage<TApp>.EmployeesGridItems;
154            aeEmployeesList[1].Click();
155            Thread.Sleep(2000);
156
157           
158            for (int count = 0; count < aeEmployeesList.Count; count++)
159            {
160                aeEmployeesList[count].Select();
161                Thread.Sleep(2000);
162
163                AutomationElement employeeTabControl = UICompositionPage<TApp>.EmployeeSummaryTabControl;
164                AutomationElementCollection employeeTabItems = UICompositionPage<TApp>.EmployeeTabItems;
165
166                employeeTabItems[1].Select();
167                Thread.Sleep(2000);
168
169                //Check if the current projects grid is loaded.
170                AutomationElement currentProjectsGrid = UICompositionPage<TApp>.SilverLightProjectsGrid;
171                GridPattern projectPattern = currentProjectsGrid.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
172                Assert.AreEqual(TestDataInfrastructure.GetTestInputData("ProjectsRowCount"+(count+1).ToString()), projectPattern.Current.RowCount.ToString());
173            }
174        }
175        #endregion
176
177        #region Private Helper methods
178
179        //private static void ValidateGeneralTabControls()
180        //{
181        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;         
182        //    empDetailsTab[0].SetFocus();
183        //    empDetailsTab[0].Select();
184        //    Thread.Sleep(2000);
185
186        //    //check all Labels (TextBlocks)
187            
188        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.FirstNameLabel);
189        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.LastNameLabel);
190        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.PhoneLabel);
191        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.EmailLabel);
192
193        //    //check all Textboxes
194        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.FirstNameTextbox);
195        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.LastNameTextBox);
196        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.PhoneTextBox);
197        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.EmailTextBox);
198        //}
199
200        //private static void ValidateLocationTabControls()
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
206        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;     
207        //    empDetailsTab[1].SetFocus();
208        //    empDetailsTab[1].Select();
209        //    Thread.Sleep(2000);
210            
211        //}
212
213        //private static void ValidateCurrentProjectsTabControls()
214        //{
215        //    //select the "Current Projects" tab
216        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
217        //    empDetailsTab[2].SetFocus();
218        //    empDetailsTab[2].Select();
219        //    Thread.Sleep(2000);
220        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.ProjectsLabel);
221        //    Assert.IsNotNull(UICompositionPage<WpfAppLauncher>.ProjectsList);
222        //}
223        ////
224        //private static void ValidateEmployeeDetailsGeneralTabData(Employee emp)
225        //{
226        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
227
228        //    Assert.AreEqual(UICompositionPage<WpfAppLauncher>.FirstNameTextbox.GetValue(), emp.FirstName);
229        //    Assert.AreEqual(UICompositionPage<WpfAppLauncher>.LastNameTextBox.GetValue(), emp.LastName);
230        //    Assert.AreEqual(UICompositionPage<WpfAppLauncher>.PhoneTextBox.GetValue(), emp.Phone);
231        //    Assert.AreEqual(UICompositionPage<WpfAppLauncher>.EmailTextBox.GetValue(), emp.Email);
232        //}
233        ////
234        //private static void ValidateEmployeeDetailsLocationTabData()
235        //{ 
236        //    //Acceptance Tests for UI Composition do not validate the location of the selected Employee
237        //    //in the Live Search Maps displayed in a HTML frame control.This method is the right place
238        //    //to do any assertions for Employee Location displayed in HTML frame control.
239
240        //   empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
241        //   empDetailsTab[1].SetFocus();
242        //   empDetailsTab[1].Select();
243        //    Thread.Sleep(2000);
244
245            
246        //}
247
248        //private static void ValidateEmployeeDetailsCurrentProjectsTabData()
249        //{
250        //    empDetailsTab = UICompositionPage<WpfAppLauncher>.EmployeeDetailsTab;
251        //    Thread.Sleep(2000);
252        //    empDetailsTab[2].SetFocus();
253        //    empDetailsTab[2].Select();
254        //    Thread.Sleep(2000);
255
256        //   // ListView projectsList = UICompositionPage<WpfAppLauncher>.ProjectsList;
257        //    AutomationElementCollection projectsList = UICompositionPage<WpfAppLauncher>.ProjectsList;
258        //    ////check if the list has two columns
259        //    //Assert.AreEqual(2, projectsList.Header.Columns.Count);            
260        //    ////check if the list has two rows
261        //    Assert.AreEqual(2, projectsList.Count-1);
262        //}
263
264        private static Employee GetEmployeeId(string count)
265        {
266            Employee emp = new Employee(1)
267            {
268                FirstName = TestDataInfrastructure.GetTestInputData("Emp_"+count+"_FirstName"),
269                LastName = TestDataInfrastructure.GetTestInputData("Emp_" +count+ "_LastName"),
270                Phone = TestDataInfrastructure.GetTestInputData("Emp_" + count + "_Phone"),
271                Email = TestDataInfrastructure.GetTestInputData("Emp_" + count + "_Email")
272            };
273
274            return emp;
275        }
276       
277        #endregion
278
279    }
280}