PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 2ms 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//===================================================================================
 17using System;
 18using System.Collections.Generic;
 19using System.Linq;
 20using System.Text;
 21using System.Windows.Automation;
 22using AcceptanceTestLibrary.ApplicationHelper;
 23using AcceptanceTestLibrary.Common;
 24
 25namespace AcceptanceTestLibrary.TestEntityBase
 26{
 27    public abstract class PageBase<TApp>
 28        where TApp : AppLauncherBase, new()
 29    {
 30        private static AutomationElement window;
 31
 32        public static AutomationElement Window
 33        {
 34            get
 35            {
 36                if (window == null)
 37                {
 38                    throw new InvalidOperationException("Window object not set exception");
 39                }
 40
 41                return window;
 42            }
 43            set
 44            {
 45                window = value;
 46            }
 47        }
 48
 49        public static AutomationElement FindControlByAutomationId(string control)
 50        {
 51            AutomationElement aeControl;
 52
 53            //find control using AutomationElement of window 
 54            aeControl = window.GetHandleById<TApp>(control);
 55            return aeControl;
 56        }
 57
 58        public static AutomationElementCollection FindControlByType(string control)
 59        {
 60            AutomationElementCollection aeControl;
 61
 62            //find control using AutomationElement of window 
 63            aeControl = window.GetHandleByControlType<TApp>(control);
 64            return aeControl;
 65        }
 66
 67        public static AutomationElementCollection FindAllControlsByAutomationId(string control)
 68        {
 69            AutomationElementCollection aeControl;
 70
 71            //find control using AutomationElement of window 
 72            aeControl = window.GetAllHandlesById<TApp>(control);
 73            return aeControl;
 74        }
 75
 76        public static AutomationElement FindControlByContent(string content)
 77        {
 78            AutomationElement aeControl;
 79
 80            //find control using AutomationElement of window 
 81            aeControl = window.GetHandleByContent<TApp>(content);
 82            return aeControl;
 83        }
 84
 85        public static AutomationElementCollection FindAllControlsByContent(string content)
 86        {
 87            AutomationElementCollection aeControl;
 88
 89            //find control using AutomationElement of window 
 90            aeControl = window.GetAllHandlesByContent<TApp>(content);
 91            return aeControl;
 92        }
 93
 94        public static AutomationElementCollection FindControlsByParent(AutomationElement parent)
 95        {
 96            AutomationElementCollection aeControlCollection;
 97
 98            //find control using AutomationElement of window 
 99            aeControlCollection = window.GetHandleByParent<TApp>(parent);
100            return aeControlCollection;
101        }
102        /// <summary>
103        /// This method disposes the static variable window.
104        /// </summary>
105        public static void DisposeWindow()
106        {
107            window = null;
108        }
109    }
110}