예제 #1
0
        public void Initialize(AutomationType selectedAutomationType)
        {
            SelectedAutomationType = selectedAutomationType;
            IsInitialized          = true;

            if (selectedAutomationType == AutomationType.UIA2)
            {
                _automation = new UIA2Automation();
            }
            else
            {
                _automation = new UIA3Automation();
            }
            _rootElement = _automation.GetDesktop();
            var desktopViewModel = new ElementViewModel(_rootElement);

            desktopViewModel.SelectionChanged += DesktopViewModel_SelectionChanged;
            desktopViewModel.LoadChildren(false);
            Elements.Add(desktopViewModel);

            // Initialize TreeWalker
            _treeWalker = _automation.TreeWalkerFactory.GetControlViewWalker();

            // Initialize hover
            _hoverMode = new HoverMode(_automation);
            _hoverMode.ElementHovered += ElementHovered;
        }
예제 #2
0
 public HoverMode(AutomationBase automation)
 {
     _automation               = automation;
     _dispatcherTimer          = new DispatcherTimer();
     _dispatcherTimer.Tick    += DispatcherTimerTick;
     _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(500);
 }
예제 #3
0
 public HoverWorker(AutomationBase automation, int targetProcessId)
 {
     _automation               = automation;
     _dispatcherTimer          = new Timer(500);
     _dispatcherTimer.Elapsed += DispatcherTimerTick;
     _targetProcessId          = targetProcessId;
 }
예제 #4
0
        public void Initialize(AutomationType selectedAutomationType)
        {
            SelectedAutomationType = selectedAutomationType;
            IsInitialized          = true;

            _automation  = selectedAutomationType == AutomationType.UIA2 ? (AutomationBase) new UIA2Automation() : new UIA3Automation();
            _rootElement = _automation.GetDesktop();
            var desktopViewModel = new ElementViewModel(_rootElement);

            desktopViewModel.SelectionChanged += DesktopViewModel_SelectionChanged;
            desktopViewModel.LoadChildren(false);
            Elements.Add(desktopViewModel);
            Elements[0].IsExpanded = true;

            // Initialize TreeWalker
            _treeWalker = _automation.TreeWalkerFactory.GetControlViewWalker();

            // Initialize hover
            _hoverMode = new HoverMode(_automation);
            _hoverMode.ElementHovered += ElementToSelectChanged;

            // Initialize focus tracking
            _focusTrackingMode = new FocusTrackingMode(_automation);
            _focusTrackingMode.ElementFocused += ElementToSelectChanged;
        }
예제 #5
0
        public WindowsTreeElement(treeelement parent, bool expanded, AutomationBase automation, AutomationElement element, ITreeWalker treeWalker) : base(parent)
        {
            Element         = new UIElement(element);
            _treeWalker     = treeWalker;
            this.automation = automation;
            RawElement      = element;
            IsExpanded      = expanded;

            string controltype  = "";
            string name         = "unknown";
            string automationid = "";

            ControlType = ControlType.Window;
            if (element.Properties.ControlType.IsSupported)
            {
                ControlType = element.Properties.ControlType.Value;
            }
            if (element.Properties.ControlType.IsSupported)
            {
                controltype = element.Properties.ControlType.Value.ToString();
            }
            if (element.Properties.Name.IsSupported)
            {
                name = element.Properties.Name.Value;
            }
            if (element.Properties.AutomationId.IsSupported)
            {
                automationid = element.Properties.AutomationId.Value;
            }
            Name = (controltype + " " + name + " " + automationid).Trim();
        }
예제 #6
0
        public ClickRecognizeWorker(AutomationBase automation, int targetProcessId)
        {
            _automation      = automation;
            _targetProcessId = targetProcessId;

            MouseWatcher.OnMouseInput += MouseWatcher_OnMouseInput;
        }
예제 #7
0
        public AutomationElement[] matches_new(AutomationBase automation, AutomationElement element, ITreeWalker _treeWalker, int count, bool isDesktop, TimeSpan timeout, bool search_descendants)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var matchs = new List <AutomationElement>();
            var c      = GetConditionsWithoutStar();

            Log.Selector("AutomationElement.matches: Searching for " + c.ToString());
            AutomationElement[] elements = null;
            if (isDesktop)
            {
                elements = element.FindAllChildren(c);
            }
            else
            {
                elements = element.FindAllDescendants(c);
            }
            Log.Selector(string.Format("AutomationElement.matches::found " + elements.Count() + " elements {0:mm\\:ss\\.fff}", sw.Elapsed));
            // var elements = element.FindAllChildren();
            foreach (var elementNode in elements)
            {
                Log.SelectorVerbose("matches::match");
                if (Match(elementNode))
                {
                    matchs.Add(elementNode);
                }
            }
            Log.Selector(string.Format("AutomationElement.matches::complete, with " + elements.Count() + " elements {0:mm\\:ss\\.fff}", sw.Elapsed));

            return(matchs.ToArray());
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="application"></param>
        /// <param name="automation"></param>
        /// <param name="func"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static Window WaitMainWindow(
            this Application application,
            AutomationBase automation,
            Func <FindBuilder, FindBuilder> func,
            RetrySettings settings)
        {
            Window?window = null;

            var element = Retry.Find(() =>
            {
                window = application.GetMainWindow(automation, Retry.DefaultInterval);

                return(window == null
                    ? null
                    : func(window.BuildFind()).FirstOrDefault());
            }, settings);

            window = window ?? throw new InvalidOperationException("Main window is null");

            // Throws right exception
            if (element == null)
            {
                func(window.BuildFind()).First();
            }

            return(window);
        }
        /// <summary>
        /// Gets all top level windows from the application.
        /// </summary>
        public Window[] GetAllTopLevelWindows(AutomationBase automation)
        {
            var desktop       = automation.GetDesktop();
            var foundElements = desktop.FindAllChildren(cf => cf.ByControlType(ControlType.Window).And(cf.ByProcessId(ProcessId)));

            return(foundElements.Select(x => x.AsWindow()).ToArray());
        }
예제 #10
0
        public static AutomationElement[] NativeArrayToManaged(AutomationBase automation, object nativeElements)
        {
            if (nativeElements == null)
            {
                return(new AutomationElement[0]);
            }
            var uia2Automation           = (UIA2Automation)automation;
            var nativeElementsCollection = nativeElements as UIA.AutomationElementCollection;

            if (nativeElementsCollection != null)
            {
                var retArray = new AutomationElement[nativeElementsCollection.Count];
                for (var i = 0; i < nativeElementsCollection.Count; i++)
                {
                    var nativeElement     = nativeElementsCollection[i];
                    var automationElement = uia2Automation.WrapNativeElement(nativeElement);
                    retArray[i] = automationElement;
                }
                return(retArray);
            }
            var nativeElementsArray = nativeElements as UIA.AutomationElement[];

            if (nativeElementsArray != null)
            {
                return(nativeElementsArray.Select(uia2Automation.WrapNativeElement).ToArray());
            }
            throw new ArgumentException("Input is neither an AutomationElementCollection nor an AutomationElement[]", nameof(nativeElements));
        }
예제 #11
0
 protected UITestBase(AutomationType automationType, TestApplicationType appType)
 {
     AutomationType  = automationType;
     ApplicationType = appType;
     ScreenshotDir   = @"c:\FailedTestsScreenshots";
     _wasTestRun     = false;
     Automation      = AutomationType == AutomationType.UIA2 ? (AutomationBase) new UIA2Automation() : new UIA3Automation();
 }
예제 #12
0
 public HoverMode()
 {
     //_automation = automation;
     _automation               = new FlaUI.UIA3.UIA3Automation();
     _dispatcherTimer          = new DispatcherTimer();
     _dispatcherTimer.Tick    += DispatcherTimerTick;
     _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(500);
 }
예제 #13
0
 protected UITestBase(AutomationType automationType, TestApplicationType appType)
 {
     AutomationType  = automationType;
     ApplicationType = appType;
     ScreenshotDir   = @"c:\FailedTestsScreenshots";
     _wasTestRun     = false;
     Automation      = TestUtilities.GetAutomation(automationType);
 }
예제 #14
0
 protected UITestBase(AutomationType automationType, TestApplicationType appType)
 {
     AutomationType  = automationType;
     ApplicationType = appType;
     FailedTestsData = @"c:\FailedTestsData";
     _wasTestRun     = false;
     Automation      = TestUtilities.GetAutomation(automationType);
     Logger.Default  = new NUnitProgressLogger();
 }
예제 #15
0
        private void Init()
        {
            _automation = new UIA3Automation();
            // Initialize TreeWalker
            _treeWalker  = _automation.TreeWalkerFactory.GetControlViewWalker();
            _rootElement = _automation.GetDesktop();

            _elementFinder = new AutomationHelper(_automation);
            _elementFinder.ControlReleasedOverElement += ControlReleasedOverElement;
        }
예제 #16
0
        private void DisposeAutomationObjects()
        {
            _elementFinder.ControlReleasedOverElement += ControlReleasedOverElement;
            _elementFinder.ControlReleasedOverElement -= ControlReleasedOverElement;

            _rootElement   = null;
            _treeWalker    = null;
            _automation    = null;
            _elementFinder = null;
        }
예제 #17
0
 public void TestSetup()
 {
     application = Application.Launch("wordpad.exe");
     // Give the application some time to start
     System.Threading.Thread.Sleep(1000);
     automation = new UIA3Automation();
     // Increase the timeouts
     automation.ConnectionTimeout  = TimeSpan.FromSeconds(automation.ConnectionTimeout.TotalSeconds * 2);
     automation.TransactionTimeout = TimeSpan.FromSeconds(automation.TransactionTimeout.TotalSeconds * 2);
 }
예제 #18
0
        public static AutomationElement[] GetTopLevelWindows(AutomationBase _automation)
        {
            var automation = (UIA3Automation)_automation;
            var result     = new List <AutomationElement>();

            if (CurrentProcessId == 0)
            {
                CurrentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
            }
            const bool   nextWindowPlz = true;
            EnumDelegate filter        = delegate(IntPtr hWnd, int lParam)
            {
                if (!IsWindowVisible(hWnd))
                {
                    return(nextWindowPlz);
                }
                uint foundThreadId = GetWindowThreadProcessId(hWnd, out uint foundProcessId);
                // if (!(foundThreadId != 0 && foundProcessId != 0)) return nextWindowPlz;
                if ((int)foundProcessId == CurrentProcessId)
                {
                    return(nextWindowPlz);
                }
                try
                {
                    var nativeAutomationElement = automation.NativeAutomation.ElementFromHandle(hWnd);
                    if (nativeAutomationElement == null)
                    {
                        return(nextWindowPlz);
                    }
                    var automationElement = automation.WrapNativeElement(nativeAutomationElement);
                    if (automationElement.Properties.IsOffscreen.IsSupported)
                    {
                        if (!automationElement.IsOffscreen)
                        {
                            result.Add(automationElement);
                        }
                    }
                    else
                    {
                        result.Add(automationElement);
                    }

                    // return okDoneScanning;
                }
                catch
                {
                    // boo UIAutomation, don't be like that
                }

                return(nextWindowPlz);
            };

            EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(result.ToArray());
        }
예제 #19
0
 public void ValidateWomenTshit()
 {
     using (var testBase = new AutomationBase("chrome"))
     {
         testBase.
         StartBrowser()
         .NavigateToLandingPage()
         .NavigateToWomenTshirt()
         .CheckHeader("T-SHIRTS ");
     }
 }
예제 #20
0
        public static IEnumerable <Window> GetTopLevelWindowsByClassName(AutomationBase automation, string className)
        {
            var desktop       = automation.GetDesktop();
            var foundElements = desktop.FindAllChildren(cf => cf
                                                        .ByControlType(ControlType.Window)
                                                        .And(cf.ByClassName(className)));

            //This expression right here eats the CPU because of the frequent COM calls

            return(foundElements.Select(x => x.AsWindow()));
        }
예제 #21
0
 public void ValidateMyAccountPage()
 {
     using (var testBase = new AutomationBase("chrome"))
     {
         testBase.
         StartBrowser()
         .NavigateToLandingPage()
         .LoginToApplication()
         .CheckHeader("MY ACCOUNT");
     }
 }
예제 #22
0
        public AutomationElement[] matches(AutomationBase automation, AutomationElement element, ITreeWalker _treeWalker, int count, bool isDesktop)
        {
            var matchs = new List <AutomationElement>();
            var c      = GetConditionsWithoutStar();

            Log.SelectorVerbose("matches::FindAllChildren");
            isDesktop = false;
            if (isDesktop) // To slow !
            {
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                Log.Information(string.Format("AutomationElement.matches::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

                Log.SelectorVerbose("Searching desktop for " + c.ToString());
                var elements = element.FindAllChildren(c);
                Log.SelectorVerbose("Done Search");
                Log.Information(string.Format("AutomationElement.matches::process elements {0:mm\\:ss\\.fff}", sw.Elapsed));
                // var elements = element.FindAllChildren();
                foreach (var elementNode in elements)
                {
                    Log.SelectorVerbose("matches::match");
                    if (Match(elementNode))
                    {
                        matchs.Add(elementNode);
                    }
                }
                Log.Information(string.Format("AutomationElement.matches::complete {0:mm\\:ss\\.fff}", sw.Elapsed));
            }
            else
            {
                var nodes       = new List <AutomationElement>();
                var elementNode = _treeWalker.GetFirstChild(element);
                var i           = 0;
                while (elementNode != null)
                {
                    nodes.Add(elementNode);
                    i++;
                    if (Match(elementNode))
                    {
                        matchs.Add(elementNode);
                    }
                    if (matchs.Count >= count)
                    {
                        break;
                    }
                    elementNode = _treeWalker.GetNextSibling(elementNode);
                }
            }
            //foreach (var _elementNode in nodes)
            //{
            //    if (match(_elementNode)) matchs.Add(_elementNode);
            //}
            return(matchs.ToArray());
        }
예제 #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="application"></param>
 /// <param name="automation"></param>
 /// <param name="func"></param>
 /// <param name="timeout"></param>
 /// <returns></returns>
 public static Window WaitMainWindow(
     this Application application,
     AutomationBase automation,
     Func <FindBuilder, FindBuilder> func,
     TimeSpan?timeout = null)
 {
     return(application.WaitMainWindow(automation, func, new RetrySettings
     {
         Timeout = timeout,
     }));
 }
예제 #24
0
 public void CheckAccountButtonUserDetails()
 {
     using (var testBase = new AutomationBase("chrome"))
     {
         testBase.
         StartBrowser()
         .NavigateToLandingPage()
         .LoginToApplication()
         .ClickHomeButton()
         .CheckAccountUser("TestUserFirstName TestUserLastName");
     }
 }
예제 #25
0
        public void TestTearDown()
        {
            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                TakeScreenshot(TestContext.CurrentContext.Test.FullName);
            }

            application.Close();
            application.Dispose();
            application = null;
            automation.Dispose();
            automation = null;
        }
예제 #26
0
        public Recorder(AutomationType automationType, CodeProviderFactory codeProviderFactory, string codeProviderName, Process targetProcess)
        {
            _automation   = automationType == AutomationType.UIA2 ? (AutomationBase) new FlaUI.UIA2.UIA2Automation() : new FlaUI.UIA3.UIA3Automation();
            _codeProvider = CreateCodeProvider(codeProviderFactory, codeProviderName, targetProcess);
            State         = RecorderState.Paused;

            // Initialize workers
            _workers.Add(new HoverWorker(_automation, targetProcess.Id));
            var click = new ClickRecognizeWorker(_automation, targetProcess.Id);

            click.ElementClicked      += Click_ElementClicked;
            click.ElementRightClicked += Click_ElementRightClicked;
            _workers.Add(click);
        }
예제 #27
0
        public Calculator(AutomationBase automation)
        {
            app = Application.LaunchStoreApp("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
            app.WaitWhileBusy();
            //mainWindow = app.GetMainWindow(automation);
            mainWindow = automation.GetDesktop().FindFirstDescendant(cf => cf.ByName("Kalkulačka")).AsWindow();
            mainWindow.SetForeground();

            /*Keyboard.TypeSimultaneously(VirtualKeyShort.LWIN, VirtualKeyShort.KEY_R);
             * Keyboard.Type("calc");
             * Wait.UntilInputIsProcessed();
             * Keyboard.Press(VirtualKeyShort.ENTER);
             * Wait.UntilInputIsProcessed();
             * mainWindow = automation.GetDesktop().FindFirstDescendant(cf => cf.ByName("Kalkulačka")).AsWindow();
             * Process p = Process.GetProcessesByName("Calculator").First();
             * app = new Application(p, true);*/
        }
예제 #28
0
        private static void CloseExistingCalculators(AutomationBase automation)
        {
            var existingHost = GetCalculatorProcess();

            if (existingHost != null)
            {
                using (var tempApp = Application.Attach(existingHost))
                {
                    var topWindows = tempApp.GetAllTopLevelWindows(automation);

                    foreach (var topWindow in topWindows)
                    {
                        topWindow.Close();
                    }
                }
            }
        }
예제 #29
0
        public WindowsTreeElement(treeelement parent, bool expanded, AutomationBase automation, AutomationElement element, ITreeWalker treeWalker) : base(parent)
        {
            Element         = new UIElement(element);
            _treeWalker     = treeWalker;
            this.automation = automation;
            RawElement      = element;
            IsExpanded      = expanded;

            string controltype  = "";
            string name         = "unknown";
            string automationid = "";

            ControlType = ControlType.Window;
            if (element.Properties.ControlType.IsSupported)
            {
                ControlType = element.Properties.ControlType.Value;
            }
            if (element.Properties.ControlType.IsSupported)
            {
                controltype = element.Properties.ControlType.Value.ToString();
            }
            if (element.Properties.Name.IsSupported)
            {
                name = element.Properties.Name.Value;
            }
            if (element.Properties.AutomationId.IsSupported)
            {
                automationid = element.Properties.AutomationId.Value;
            }
            Name = (controltype + " " + name + " " + automationid).Trim();
            if (string.IsNullOrEmpty(Name))
            {
                try
                {
                    var c = element.Properties.ControlType.ValueOrDefault;
                    controltype = c.ToString();
                    Name        = (controltype + " " + name + " " + automationid).Trim();
                }
                catch (Exception)
                {
                    throw;
                }
                var b = true;
            }
        }
예제 #30
0
        /// <summary>
        /// Converts a native array of elements to an array of managed elements.
        /// </summary>
        /// <param name="automation">The automation to use for the conversion.</param>
        /// <param name="nativeElements">The native array to convert.</param>
        /// <returns>The array of managed elements.</returns>
        public static AutomationElement[] NativeArrayToManaged(AutomationBase automation, object nativeElements)
        {
            if (nativeElements == null)
            {
                return(new AutomationElement[0]);
            }
            var uia3Automation     = (UIA3Automation)automation;
            var nativeElementArray = (UIA.IUIAutomationElementArray)nativeElements;
            var retArray           = new AutomationElement[nativeElementArray.Length];

            for (var i = 0; i < nativeElementArray.Length; i++)
            {
                var nativeElement     = nativeElementArray.GetElement(i);
                var automationElement = uia3Automation.WrapNativeElement(nativeElement);
                retArray[i] = automationElement;
            }
            return(retArray);
        }