From e6a6e0ccad005e1e96b81c1044948b2f1ec407fd Mon Sep 17 00:00:00 2001 From: Roman Baeriswyl Date: Fri, 17 Apr 2020 16:42:12 +0200 Subject: [PATCH] One more try to fix the test --- src/FlaUI.Core.UITests/SearchTests.cs | 9 ++++-- .../TestFramework/UtilityMethods.cs | 31 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/FlaUI.Core.UITests/SearchTests.cs b/src/FlaUI.Core.UITests/SearchTests.cs index 3fb0b8e2f..e40844d98 100644 --- a/src/FlaUI.Core.UITests/SearchTests.cs +++ b/src/FlaUI.Core.UITests/SearchTests.cs @@ -4,6 +4,7 @@ using FlaUI.Core.Definitions; using FlaUI.Core.Input; using FlaUI.Core.Tools; +using FlaUI.Core.UITests.TestFramework; using FlaUI.Core.WindowsAPI; using FlaUI.UIA3; using NUnit.Framework; @@ -45,6 +46,10 @@ public void SearchWithRetryTest() [Test] public void SearchWithAccessibilityRole() { + if (UtilityMethods.GetUiaVersion(AutomationType.UIA3) != AutomationType.UIA3) + { + Assert.Ignore("Only run test in UIA3 context"); + } using (var app = Application.Launch("notepad.exe")) { using (var automation = new UIA3Automation()) @@ -53,9 +58,7 @@ public void SearchWithAccessibilityRole() Assert.That(window, Is.Not.Null); Assert.That(window.Title, Is.Not.Null); - var editableText = Retry.WhileNull(() => - window.FindFirstChild(new PropertyCondition(automation.PropertyLibrary.LegacyIAccessible.Role, AccessibilityRole.ROLE_SYSTEM_TEXT)), - timeout: TimeSpan.FromSeconds(5)).Result; + var editableText = window.FindFirstChild(new PropertyCondition(automation.PropertyLibrary.LegacyIAccessible.Role, AccessibilityRole.ROLE_SYSTEM_TEXT)); Assert.That(editableText, Is.Not.Null); Assert.That(editableText.Patterns.Text.IsSupported, Is.True); } diff --git a/src/FlaUI.Core.UITests/TestFramework/UtilityMethods.cs b/src/FlaUI.Core.UITests/TestFramework/UtilityMethods.cs index a5b6f77c6..a2cc25abc 100644 --- a/src/FlaUI.Core.UITests/TestFramework/UtilityMethods.cs +++ b/src/FlaUI.Core.UITests/TestFramework/UtilityMethods.cs @@ -16,15 +16,14 @@ public static class UtilityMethods { public static AutomationBase GetAutomation(AutomationType automationType) { - if (TestContext.Parameters.Exists("uia")) + // Get and validate the version + var uiaVersion = GetUiaVersion(automationType); + if ((automationType == AutomationType.UIA2 && uiaVersion != AutomationType.UIA2) || + (automationType == AutomationType.UIA3 && uiaVersion != AutomationType.UIA3)) { - var uiaVersion = Convert.ToInt32(TestContext.Parameters["uia"]); - if ((automationType == AutomationType.UIA2 && uiaVersion != 2) || - (automationType == AutomationType.UIA3 && uiaVersion != 3)) - { - Assert.Inconclusive($"UIA parameter set to {uiaVersion} but automation of type {automationType} is requested"); - } + Assert.Inconclusive($"UIA parameter set to {uiaVersion} but automation of type {automationType} is requested"); } + switch (automationType) { case AutomationType.UIA2: @@ -36,6 +35,24 @@ public static AutomationBase GetAutomation(AutomationType automationType) } } + public static AutomationType GetUiaVersion(AutomationType defaultIfNonExistent) + { + if (!TestContext.Parameters.Exists("uia")) + { + return defaultIfNonExistent; + } + var uiaVersion = Convert.ToInt32(TestContext.Parameters["uia"]); + switch (uiaVersion) + { + case 2: + return AutomationType.UIA2; + case 3: + return AutomationType.UIA3; + default: + throw new ArgumentOutOfRangeException("uia", uiaVersion, null); + } + } + /// /// Closes the given window and invokes the "Don't save" button ///