diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/DialogHelpers.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/DialogHelpers.cs index ab838f2448ed5f01dc49a553511e0dde9002f9de..2e8467b40cbbe366f91ed5e9346d43248260bd2b 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/DialogHelpers.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/DialogHelpers.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; @@ -11,6 +13,23 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess { public static class DialogHelpers { + /// + /// Returns an representing the open dialog with automation ID + /// . + /// Throws an if an open dialog with that name cannot be + /// found. + /// + public static AutomationElement GetOpenDialog(int visualStudioHWnd, string dialogAutomationName) + { + var dialogAutomationElement = FindDialog(visualStudioHWnd, dialogAutomationName, isOpen: true); + if (dialogAutomationElement == null) + { + throw new InvalidOperationException($"Expected the {dialogAutomationName} dialog to be open, but it is not."); + } + + return dialogAutomationElement; + } + public static AutomationElement FindDialog(int visualStudioHWnd, string dialogAutomationName, bool isOpen) { return Retry( diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/Editor_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/Editor_InProc.cs index 38ded56d4e7fc1773f6d90c3c58725c752a0bc85..cf5866d582c30697faaf7afbc2cc6b09f0969f7e 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/Editor_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/Editor_InProc.cs @@ -122,6 +122,8 @@ public string GetLineTextBeforeCaret() return text.Substring(0, bufferPosition.Position - line.Start); }); + + public string GetLineTextAfterCaret() => ExecuteOnActiveView(view => { @@ -420,11 +422,7 @@ public void VerifyDialog(string dialogAutomationId, bool isOpen) public void DialogSendKeys(string dialogAutomationName, string keys) { - var dialogAutomationElement = DialogHelpers.FindDialog(GetDTE().MainWindow.HWnd, dialogAutomationName, isOpen: true); - if (dialogAutomationElement == null) - { - throw new InvalidOperationException($"Expected the {dialogAutomationName} dialog to be open, but it is not."); - } + var dialogAutomationElement = DialogHelpers.GetOpenDialog(GetDTE().MainWindow.HWnd, dialogAutomationName); dialogAutomationElement.SetFocus(); SendKeys.SendWait(keys); @@ -432,29 +430,10 @@ public void DialogSendKeys(string dialogAutomationName, string keys) public void PressDialogButton(string dialogAutomationName, string buttonAutomationName) { - var dialogAutomationElement = DialogHelpers.FindDialog(GetDTE().MainWindow.HWnd, dialogAutomationName, isOpen: true); - if (dialogAutomationElement == null) - { - throw new InvalidOperationException($"Expected the {dialogAutomationName} dialog to be open, but it is not."); - } - - Condition condition = new PropertyCondition(AutomationElement.AutomationIdProperty, buttonAutomationName); - - var buttonAutomationElement = dialogAutomationElement.FindFirst(TreeScope.Descendants, condition); + var dialogAutomationElement = DialogHelpers.GetOpenDialog(GetDTE().MainWindow.HWnd, dialogAutomationName); - if (buttonAutomationElement == null) - { - throw new InvalidOperationException($"Could not find the {buttonAutomationName} button in the {dialogAutomationName} dialog"); - } - - if (buttonAutomationElement.TryGetCurrentPattern(InvokePattern.Pattern, out var invokePattern)) - { - (invokePattern as InvokePattern).Invoke(); - } - else - { - throw new InvalidOperationException($"The element {buttonAutomationName} does not have an InvokePattern. Please make sure that it is the correct control"); - } + var buttonAutomationElement = dialogAutomationElement.FindDescendantByAutomationId(buttonAutomationName); + buttonAutomationElement.Invoke(); } } }