Przeglądaj źródła

Make integration tests pass on MacOS.

Steven Kirk 3 lat temu
rodzic
commit
f4d9d4cc13

+ 17 - 3
src/Avalonia.Controls/Automation/Peers/ComboBoxAutomationPeer.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using Avalonia.Automation.Provider;
 using Avalonia.Controls;
 
@@ -7,12 +8,13 @@ using Avalonia.Controls;
 namespace Avalonia.Automation.Peers
 {
     public class ComboBoxAutomationPeer : SelectingItemsControlAutomationPeer,
-        IExpandCollapseProvider
+        IExpandCollapseProvider,
+        IValueProvider
     {
         private UnrealizedSelectionPeer[]? _selection;
 
         public ComboBoxAutomationPeer(ComboBox owner)
-            : base(owner) 
+            : base(owner)
         {
         }
 
@@ -22,7 +24,19 @@ namespace Avalonia.Automation.Peers
         public bool ShowsMenu => true;
         public void Collapse() => Owner.IsDropDownOpen = false;
         public void Expand() => Owner.IsDropDownOpen = true;
+        bool IValueProvider.IsReadOnly => true;
 
+        string? IValueProvider.Value
+        {
+            get
+            {
+                var selection = GetSelection();
+                return selection.Count == 1 ? selection[0].GetName() : null;
+            }
+        }
+        
+        void IValueProvider.SetValue(string? value) => throw new NotSupportedException();
+        
         protected override AutomationControlType GetAutomationControlTypeCore()
         {
             return AutomationControlType.ComboBox;

+ 3 - 2
tests/Avalonia.IntegrationTests.Appium/ComboBoxTests.cs

@@ -1,4 +1,5 @@
 using OpenQA.Selenium.Appium;
+using OpenQA.Selenium.Appium.Mac;
 using Xunit;
 
 namespace Avalonia.IntegrationTests.Appium
@@ -24,8 +25,8 @@ namespace Avalonia.IntegrationTests.Appium
 
             Assert.Equal(string.Empty, comboBox.Text);
 
-            comboBox.Click();
-            comboBox.FindElementByName("Bar").Click();
+            ((MacElement)comboBox).Click();
+            _session.FindElementByName("Bar").ClickListItem();
 
             Assert.Equal("Bar", comboBox.Text);
         }

+ 19 - 0
tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Runtime.InteropServices;
 using OpenQA.Selenium.Appium;
+using OpenQA.Selenium.Appium.MultiTouch;
+using OpenQA.Selenium.Interactions;
 
 namespace Avalonia.IntegrationTests.Appium
 {
@@ -17,6 +19,23 @@ namespace Avalonia.IntegrationTests.Appium
                 _ => throw new ArgumentOutOfRangeException($"Unexpected IsChecked value.")
             };
 
+        public static void ClickListItem(this AppiumWebElement element)
+        {
+            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            {
+                element.Click();
+            }
+            else
+            {
+                // List items don't respond to performClick on MacOS, so instead send a physical click as VoiceOver
+                // does.
+                var action = new Actions(element.WrappedDriver);
+                action.MoveToElement(element);
+                action.Click();
+                action.Perform();
+            }
+        }
+
         public static string GetAttribute(AppiumWebElement element, string windows, string macOS)
         {
             return element.GetAttribute(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? windows : macOS);

+ 1 - 1
tests/Avalonia.IntegrationTests.Appium/MenuTests.cs

@@ -18,7 +18,7 @@ namespace Avalonia.IntegrationTests.Appium
             Assert.Equal("File", fileMenu.Text);
         }
 
-        [Fact]
+        [PlatformFact(SkipOnOSX = true)]
         public void Open()
         {
             var fileMenu = _session.FindElementByAccessibilityId("FileMenu");

+ 1 - 1
tests/Avalonia.IntegrationTests.Appium/PlatformFactAttribute.cs

@@ -14,7 +14,7 @@ namespace Avalonia.IntegrationTests.Appium
                 if (SkipOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                     return "Ignored on Windows";
                 if (SkipOnOSX && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
-                    return "Ignored on Windows";
+                    return "Ignored on MacOS";
                 return null;
             }
             set => throw new NotSupportedException();