PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/AcceptanceTestLibrary/AcceptanceTestLibrary/TestEntityBase/Page/PageBase.cs

#
C# | 110 lines | 70 code | 15 blank | 25 comment | 2 complexity | 02902ce47f0fb44f3dff5fbf0e5e0949 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 System.Windows.Automation;
  22. using AcceptanceTestLibrary.ApplicationHelper;
  23. using AcceptanceTestLibrary.Common;
  24. namespace AcceptanceTestLibrary.TestEntityBase
  25. {
  26. public abstract class PageBase<TApp>
  27. where TApp : AppLauncherBase, new()
  28. {
  29. private static AutomationElement window;
  30. public static AutomationElement Window
  31. {
  32. get
  33. {
  34. if (window == null)
  35. {
  36. throw new InvalidOperationException("Window object not set exception");
  37. }
  38. return window;
  39. }
  40. set
  41. {
  42. window = value;
  43. }
  44. }
  45. public static AutomationElement FindControlByAutomationId(string control)
  46. {
  47. AutomationElement aeControl;
  48. //find control using AutomationElement of window
  49. aeControl = window.GetHandleById<TApp>(control);
  50. return aeControl;
  51. }
  52. public static AutomationElementCollection FindControlByType(string control)
  53. {
  54. AutomationElementCollection aeControl;
  55. //find control using AutomationElement of window
  56. aeControl = window.GetHandleByControlType<TApp>(control);
  57. return aeControl;
  58. }
  59. public static AutomationElementCollection FindAllControlsByAutomationId(string control)
  60. {
  61. AutomationElementCollection aeControl;
  62. //find control using AutomationElement of window
  63. aeControl = window.GetAllHandlesById<TApp>(control);
  64. return aeControl;
  65. }
  66. public static AutomationElement FindControlByContent(string content)
  67. {
  68. AutomationElement aeControl;
  69. //find control using AutomationElement of window
  70. aeControl = window.GetHandleByContent<TApp>(content);
  71. return aeControl;
  72. }
  73. public static AutomationElementCollection FindAllControlsByContent(string content)
  74. {
  75. AutomationElementCollection aeControl;
  76. //find control using AutomationElement of window
  77. aeControl = window.GetAllHandlesByContent<TApp>(content);
  78. return aeControl;
  79. }
  80. public static AutomationElementCollection FindControlsByParent(AutomationElement parent)
  81. {
  82. AutomationElementCollection aeControlCollection;
  83. //find control using AutomationElement of window
  84. aeControlCollection = window.GetHandleByParent<TApp>(parent);
  85. return aeControlCollection;
  86. }
  87. /// <summary>
  88. /// This method disposes the static variable window.
  89. /// </summary>
  90. public static void DisposeWindow()
  91. {
  92. window = null;
  93. }
  94. }
  95. }