Esempio n. 1
0
        public static ButtonControl FromControlDef(IControlLocatorDef controlLocatorDef)
        {
            var sut    = WinControlUnderTest.FromControlDef(controlLocatorDef);
            var button = new ButtonControl();

            button.SystemUnderTest(sut);
            return(button);
        }
Esempio n. 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets a test control. </summary>
        ///
        /// <typeparam name="T">    Generic type parameter. </typeparam>
        /// <param name="controlLocatorDef">   The control def. </param>
        ///
        /// <returns>   The test control< t> </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public virtual T GetTestControl <T>(IControlLocatorDef controlLocatorDef) where T : ITestControl
        {
            ITestControl testControl  = null;
            Type         typeToCreate = typeof(T);
            IntPtr       handle       = controlLocatorDef.Handle; //waits and retries done at this level.
            string       wndClassName = (handle == IntPtr.Zero) ? string.Empty : GetWindowClassName(handle);

            if (IsTestControlRegistered(wndClassName))
            {
                typeToCreate = testControls[wndClassName] as Type;
                if ((typeToCreate.IsClass) && typeof(T).IsClass)
                {
                    //if registration has class in it then type use T as a override
                    typeToCreate = typeof(T);
                }
            }
            try
            {
                try
                {
                    testControl = Activator.CreateInstance(typeToCreate, this) as ITestControl;
                }
                catch
                {
                    testControl = null;
                }

                if (testControl == null)
                {
                    testControl = Activator.CreateInstance(typeToCreate) as ITestControl;
                }

                ITestContextAware appSut = testControl as ITestContextAware;
                if (appSut != null)
                {
                    appSut.ApplicationUnderTest = this;
                }

                testControl.SystemUnderTest(controlLocatorDef);
                testControl.WndClassName = wndClassName;
            }

            catch (Exception e)
            {
                _logger.Error(e.ToString());
            }

            return((T)testControl);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Initializes this object from the given from control def. </summary>
        ///
        /// <param name="controlLocatorDef">   The control def. </param>
        ///
        /// <returns>   . </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public static WinControlUnderTest FromControlDef(IControlLocatorDef controlLocatorDef, bool bCreateHandle = true)
        {
            var uiaSut = new WinControlUnderTest
            {
                _controlLocatorDef = controlLocatorDef,
            };

            uiaSut.SetUnderlyingObject(null);
            if (bCreateHandle)
            {
                var handle = controlLocatorDef.Handle;
                if (handle != IntPtr.Zero)
                {
                    uiaSut.SetUnderlyingObject(AutomationElement.FromHandle(handle));
                }
            }
            return(uiaSut);
        }
Esempio n. 4
0
 public override IElementUnderTest GetAutomationObject(IControlLocatorDef controlLocatorDef, bool bCreateHandle = true)
 {
     controlLocatorDef.SetRetryTime(20, 50);
     _accObjectTest = WinControlUnderTest.FromHandle(controlLocatorDef.Handle);
     return(_accObjectTest);
 }
Esempio n. 5
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   System under test if exists timeout. </summary>
 ///
 ///<param name="controlLocatorDef"></param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public virtual void SystemUnderTestIfExistsTimeout(IControlLocatorDef controlLocatorDef)
 {
     _controlLocatorDef       = controlLocatorDef;
     controlUnderTestInstance = GetAutomationObject(controlLocatorDef);
     _ifExists = true;
 }
Esempio n. 6
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Tests system under. </summary>
 ///
 /// <param name="controlLocatorDef">   The control def. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public virtual void SystemUnderTest(IControlLocatorDef controlLocatorDef)
 {
     _controlLocatorDef       = controlLocatorDef;
     controlUnderTestInstance = GetAutomationObject(controlLocatorDef, false);
     _ifExists = false;
 }
Esempio n. 7
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>    Gets an automation object. </summary>
 ///
 /// <param name="controlLocatorDef">    The control def. </param>
 ///
 /// <returns>    The automation object. </returns>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public virtual IElementUnderTest GetAutomationObject(IControlLocatorDef controlLocatorDef, bool bCreateHandle = true)
 {
     return(WinControlUnderTest.FromControlDef(controlLocatorDef));
 }
Esempio n. 8
0
 public override IElementUnderTest GetAutomationObject(IControlLocatorDef controlLocatorDef, bool bCreateHandle = true)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Gets an automation object. </summary>
 ///
 /// <typeparam name="T">    Generic type parameter. </typeparam>
 /// <param name="controlLocatorDef">   The control def. </param>
 ///
 /// <returns>   The automation object< t> </returns>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public virtual T GetAutomationObject <T>(IControlLocatorDef controlLocatorDef) where T : ITestControl
 {
     return(GetTestControl <T>(controlLocatorDef));
 }