Esempio n. 1
0
        public static OverwriteFileDialog Wait(VisualStudioApp app)
        {
            var hwnd = app.WaitForDialog();

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "Did not find OverwriteFileDialog");
            var element = AutomationElement.FromHandle(hwnd);

            try {
                Assert.IsNotNull(element.FindFirst(
                                     TreeScope.Descendants,
                                     new PropertyCondition(AutomationElement.AutomationIdProperty, "_allItems")
                                     ), "Not correct dialog - missing '_allItems'");
                Assert.IsNotNull(element.FindFirst(
                                     TreeScope.Descendants,
                                     new PropertyCondition(AutomationElement.AutomationIdProperty, "_yes")
                                     ), "Not correct dialog - missing '_yes'");

                var res = new OverwriteFileDialog(app, element);
                element = null;
                return(res);
            } finally {
                if (element != null)
                {
                    AutomationWrapper.DumpElement(element);
                }
            }
        }
Esempio n. 2
0
        public AutomationElement this[Guid tabGuid]
        {
            get
            {
                var tabItem = FindByAutomationId("PropPage_" + tabGuid.ToString("n").ToLower());
                Assert.IsNotNull(tabItem, "Failed to find page");

                AutomationWrapper.DumpElement(tabItem);
                foreach (var p in tabItem.GetSupportedPatterns())
                {
                    Console.WriteLine("Supports {0}", p.ProgrammaticName);
                }

                try
                {
                    tabItem.GetInvokePattern().Invoke();
                }
                catch (InvalidOperationException)
                {
                    AutomationWrapper.DoDefaultAction(tabItem);
                }

                return(FindByAutomationId("PageHostingPanel"));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Checks the text of a dialog and dismisses it.
        ///
        /// dlgField is the field to check the text of.
        /// buttonId is the button to press to dismiss.
        /// </summary>
        private static void CheckAndDismissDialog(string[] text, int dlgField, IntPtr buttonId)
        {
            var        handle  = new IntPtr(VSTestContext.DTE.MainWindow.HWnd);
            IVsUIShell uiShell = VSTestContext.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 20 && hwnd == handle; i++)
            {
                System.Threading.Thread.Sleep(500);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "hwnd is null, We failed to get the dialog");
            Assert.AreNotEqual(handle, hwnd, "hwnd is Dte.MainWindow, We failed to get the dialog");
            Console.WriteLine("Ending dialog: ");
            AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
            Console.WriteLine("--------");
            try {
                StringBuilder title = new StringBuilder(4096);
                Assert.AreNotEqual(NativeMethods.GetDlgItemText(hwnd, dlgField, title, title.Capacity), (uint)0);

                string t = title.ToString();
                AssertUtil.Contains(t, text);
            } finally {
                NativeMethods.EndDialog(hwnd, buttonId);
            }
        }
Esempio n. 4
0
        private AutomationElement FindChildOfWorkspaceHelper(string[] path, bool assertOnFailure)
        {
            var projElement = Nodes.FirstOrDefault()?.Element;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(projElement, "Did not find solution explorer workspace root element");
            }

            if (projElement == null)
            {
                return(null);
            }

            var itemElement = path.Any() ? FindNode(
                projElement.FindAll(TreeScope.Children, Condition.TrueCondition),
                path,
                0
                ) : projElement;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(itemElement, string.Format("Did not find element <{0}>", string.Join("\\", path)));
            }
            return(itemElement);
        }
Esempio n. 5
0
        public void FocusLanguageNode(string name = "Python")
        {
            if (InstalledTemplates == null)
            {
                Console.WriteLine("Failed to find InstalledTemplates:");
                AutomationWrapper.DumpElement(Element);
            }
#if DEV11_OR_LATER
            var item = InstalledTemplates.FindItem("Templates", name);
            if (item == null)
            {
                item = InstalledTemplates.FindItem("Templates", "Other Languages", name);
            }
#else
            var item = InstalledTemplates.FindItem("Other Languages", name);
            if (item == null)
            {
                // VS can be configured so that there is no Other Languages category
                item = InstalledTemplates.FindItem(name);
            }
#endif
            if (item == null)
            {
                Console.WriteLine("Failed to find templates for " + name);
                AutomationWrapper.DumpElement(InstalledTemplates.Element);
            }
            item.SetFocus();
        }
Esempio n. 6
0
        public void DismissAllDialogs() {
            int foundWindow = 2;

            while (foundWindow != 0) {
                IVsUIShell uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
                if (uiShell == null) {
                    return;
                }

                IntPtr hwnd;
                uiShell.GetDialogOwnerHwnd(out hwnd);

                for (int j = 0; j < 10 && hwnd == _mainWindowHandle; j++) {
                    System.Threading.Thread.Sleep(100);
                    uiShell.GetDialogOwnerHwnd(out hwnd);
                }

                //We didn't see any dialogs
                if (hwnd == IntPtr.Zero || hwnd == _mainWindowHandle) {
                    foundWindow--;
                    continue;
                }

                //MessageBoxButton.Abort
                //MessageBoxButton.Cancel
                //MessageBoxButton.No
                //MessageBoxButton.Ok
                //MessageBoxButton.Yes
                //The second parameter is going to be the value returned... We always send Ok
                Debug.WriteLine("Dismissing dialog");
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
                NativeMethods.EndDialog(hwnd, new IntPtr(1));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Checks the text of a dialog and dismisses it.
        ///
        /// dlgField is the field to check the text of.
        /// buttonId is the button to press to dismiss.
        /// </summary>
        private void CheckAndDismissDialog(string[] text, int dlgField, string buttonId, bool assertIfNoDialog)
        {
            var        handle  = new IntPtr(Dte.MainWindow.HWnd);
            IVsUIShell uiShell = ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            uiShell.GetDialogOwnerHwnd(out IntPtr hwnd);

            for (int i = 0; i < 20 && hwnd == handle; i++)
            {
                System.Threading.Thread.Sleep(500);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (!assertIfNoDialog && (hwnd == IntPtr.Zero || hwnd == handle))
            {
                return;
            }

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "hwnd is null, We failed to get the dialog");
            Assert.AreNotEqual(handle, hwnd, "hwnd is Dte.MainWindow, We failed to get the dialog");
            Console.WriteLine("Ending dialog: ");
            AutomationDialog dlg = new AutomationDialog(this, AutomationElement.FromHandle(hwnd));

            AutomationWrapper.DumpElement(dlg.Element);
            Console.WriteLine("--------");

            bool closed = false;

            try
            {
                string title = dlg.Text;
                if (assertIfNoDialog)
                {
                    AssertUtil.Contains(title, text);
                }
                else if (!text.All(title.Contains))
                {
                    // We do not want to close the dialog now, as it may be expected
                    // by a later part of the test.
                    closed = true;
                }
            }
            finally
            {
                if (!closed)
                {
                    if (buttonId == MessageBoxButton.Close.ToString())
                    {
                        dlg.WaitForClosed(TimeSpan.FromSeconds(10.0), dlg.CloseWindow);
                    }
                    else if (!dlg.ClickButtonAndClose(buttonId))
                    {
                        dlg.CloseWindow();
                    }
                }
            }
        }
Esempio n. 8
0
 private static T Pattern <T>(this AutomationElement node, AutomationPattern pattern) where T : BasePattern
 {
     try {
         return((T)node.GetCurrentPattern(pattern));
     } catch (InvalidOperationException) {
         Console.WriteLine("{0} pattern is not supported by {1}.", pattern.ProgrammaticName, node.Current.Name);
         AutomationWrapper.DumpElement(node);
         throw;
     }
 }
Esempio n. 9
0
        private AutomationElement FindChildOfProjectHelper(EnvDTE.Project project, string[] path, bool assertOnFailure)
        {
            var sln      = project.DTE.Solution;
            int count    = sln.Projects.OfType <EnvDTE.Project>().Count(p => !string.IsNullOrEmpty(p.FullName));
            var slnLabel = string.Format(
                "Solution '{0}' ({1} project{2})",
                Path.GetFileNameWithoutExtension(sln.FullName),
                count,
                count == 1 ? "" : "s"
                );

            var slnElements = Element.FindAll(TreeScope.Children, new PropertyCondition(
                                                  AutomationElement.NameProperty, slnLabel
                                                  ));
            int slnCount = slnElements.OfType <AutomationElement>().Count();

            if (assertOnFailure)
            {
                Assert.AreEqual(1, slnCount, string.Format("Did not find single node <{0}>", slnLabel));
            }
            else if (slnCount != 1)
            {
                return(null);
            }
            var slnElement = slnElements.Cast <AutomationElement>().Single();

            var projLabel    = project.Name;
            var projElements = slnElement.FindAll(TreeScope.Children, new PropertyCondition(
                                                      AutomationElement.NameProperty, projLabel
                                                      ));
            int projCount = projElements.OfType <AutomationElement>().Count();

            if (assertOnFailure)
            {
                Assert.AreEqual(1, projCount, string.Format("Did not find single node <{0}>", projLabel));
            }
            else if (projCount != 1)
            {
                return(null);
            }
            var projElement = projElements.Cast <AutomationElement>().Single();

            var itemElement = path.Any() ? FindNode(
                projElement.FindAll(TreeScope.Children, Condition.TrueCondition),
                path,
                0
                ) : projElement;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(itemElement, string.Format("Did not find element <{0}\\{1}\\{2}>", slnLabel, projLabel, string.Join("\\", path)));
            }
            return(itemElement);
        }
Esempio n. 10
0
        /// <summary>
        /// Waits for no dialog. If a dialog appears before the timeout expires
        /// then the test fails and the dialog is closed.
        /// </summary>
        public void WaitForNoDialog(TimeSpan timeout) {
            IVsUIShell uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
            IntPtr hwnd;
            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 100 && hwnd == _mainWindowHandle; i++) {
                System.Threading.Thread.Sleep((int)timeout.TotalMilliseconds / 100);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (hwnd != (IntPtr)_mainWindowHandle) {
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
                NativeMethods.EndDialog(hwnd, (IntPtr)(int)MessageBoxButton.Cancel);
                Assert.Fail("Dialog appeared - see output for details");
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Dumps the current top-level window in VS
        /// </summary>
        public static void DumpVS()
        {
            IVsUIShell uiShell = VSTestContext.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));

            // if we have a dialog open dump the main VS window too
            var mainHwnd = new IntPtr(VSTestContext.DTE.MainWindow.HWnd);

            if (mainHwnd != hwnd)
            {
                Console.WriteLine("VS: ");
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(mainHwnd));
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Dumps the current top-level window in VS
        /// </summary>
        public static void DumpVS()
        {
            var sp = ServiceProvider.GlobalProvider;

            if (sp == null)
            {
                return;
            }

            IVsUIShell uiShell = sp.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));

            // if we have a dialog open dump the main VS window too
            var mainHwnd = new IntPtr(((EnvDTE.DTE)sp.GetService(typeof(EnvDTE.DTE))).MainWindow.HWnd);

            if (mainHwnd != hwnd)
            {
                Console.WriteLine("VS: ");
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(mainHwnd));
            }
        }