Skip to content

Commit

Permalink
One more try to fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roemer committed Apr 17, 2020
1 parent ae0e306 commit e6a6e0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/FlaUI.Core.UITests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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);
}
Expand Down
31 changes: 24 additions & 7 deletions src/FlaUI.Core.UITests/TestFramework/UtilityMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
}
}

/// <summary>
/// Closes the given window and invokes the "Don't save" button
/// </summary>
Expand Down

0 comments on commit e6a6e0c

Please sign in to comment.