diff --git a/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs b/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs index a31981bd2f9..45933913e06 100644 --- a/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs +++ b/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs @@ -12,9 +12,10 @@ namespace Avalonia.IntegrationTests.Appium { public record class WindowChrome( - AppiumWebElement Close, - AppiumWebElement Minimize, - AppiumWebElement Maximize); + AppiumWebElement? Close, + AppiumWebElement? Minimize, + AppiumWebElement? Maximize, + AppiumWebElement? FullScreen); internal static class ElementExtensions { @@ -25,10 +26,11 @@ public static WindowChrome GetChromeButtons(this AppiumWebElement window) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - var closeButton = window.FindElementByXPath("//XCUIElementTypeButton[1]"); - var fullscreenButton = window.FindElementByXPath("//XCUIElementTypeButton[2]"); - var minimizeButton = window.FindElementByXPath("//XCUIElementTypeButton[3]"); - return new(closeButton, minimizeButton, fullscreenButton); + var closeButton = window.FindElementsByAccessibilityId("_XCUI:CloseWindow").FirstOrDefault(); + var fullscreenButton = window.FindElementsByAccessibilityId("_XCUI:FullScreenWindow").FirstOrDefault(); + var minimizeButton = window.FindElementsByAccessibilityId("_XCUI:MinimizeWindow").FirstOrDefault(); + var zoomButton = window.FindElementsByAccessibilityId("_XCUI:ZoomWindow").FirstOrDefault(); + return new(closeButton, minimizeButton, zoomButton, fullscreenButton); } throw new NotSupportedException("GetChromeButtons not supported on this platform."); @@ -143,7 +145,7 @@ public static IDisposable OpenWindowWithClick(this AppiumWebElement element) var text = windows.Select(x => x.Text).ToList(); var newWindow = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")) .First(x => x.Text == newWindowTitle); - var (close, _, _) = ((AppiumWebElement)newWindow).GetChromeButtons(); + var close = ((AppiumWebElement)newWindow).GetChromeButtons().Close; close!.Click(); Thread.Sleep(1000); }); diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs index c5f664b0ba2..19a022e8370 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs @@ -85,7 +85,7 @@ public void WindowOrder_Modal_Dialog_Stays_InFront_Of_Parent_When_In_Fullscreen( var mainWindow = GetWindow("MainWindow"); var buttons = mainWindow.GetChromeButtons(); - buttons.Maximize.Click(); + buttons.FullScreen.Click(); Thread.Sleep(500); @@ -239,17 +239,18 @@ public void WindowOrder_Owned_Is_Correct_After_Closing_Window() public void Parent_Window_Has_Disabled_ChromeButtons_When_Modal_Dialog_Shown() { var window = GetWindow("MainWindow"); - var (closeButton, miniaturizeButton, zoomButton) = window.GetChromeButtons(); + var windowChrome = window.GetChromeButtons(); - Assert.True(closeButton.Enabled); - Assert.True(zoomButton.Enabled); - Assert.True(miniaturizeButton.Enabled); + Assert.True(windowChrome.Close.Enabled); + Assert.True(windowChrome.Maximize.Enabled); + Assert.True(windowChrome.Maximize.Enabled); + Assert.Null(windowChrome.FullScreen.Enabled); using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner)) { - Assert.False(closeButton.Enabled); - Assert.False(zoomButton.Enabled); - Assert.False(miniaturizeButton.Enabled); + Assert.False(windowChrome.Close.Enabled); + Assert.False(windowChrome.Maximize.Enabled); + Assert.False(windowChrome.Minimize.Enabled); } } @@ -259,11 +260,11 @@ public void Minimize_Button_Is_Disabled_On_Modal_Dialog() using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner)) { var secondaryWindow = GetWindow("SecondaryWindow"); - var (closeButton, miniaturizeButton, zoomButton) = secondaryWindow.GetChromeButtons(); + var windowChrome = secondaryWindow.GetChromeButtons(); - Assert.True(closeButton.Enabled); - Assert.True(zoomButton.Enabled); - Assert.False(miniaturizeButton.Enabled); + Assert.True(windowChrome.Close.Enabled); + Assert.True(windowChrome.Maximize.Enabled); + Assert.False(windowChrome.Minimize.Enabled); } } @@ -274,7 +275,7 @@ public void Minimize_Button_Disabled_Owned_Window(ShowWindowMode mode) using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual)) { var secondaryWindow = GetWindow("SecondaryWindow"); - var (_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons(); + var miniaturizeButton = secondaryWindow.GetChromeButtons().Minimize; Assert.False(miniaturizeButton.Enabled); } @@ -288,7 +289,7 @@ public void Minimize_Button_Minimizes_Window(ShowWindowMode mode) using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual)) { var secondaryWindow = GetWindow("SecondaryWindow"); - var (_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons(); + var miniaturizeButton = secondaryWindow.GetChromeButtons().Minimize; miniaturizeButton.Click(); Thread.Sleep(1000); @@ -344,7 +345,7 @@ public void Window_Has_Disabled_Zoom_Button_When_CanResize_Is_False(ShowWindowMo using (OpenWindow(null, mode, WindowStartupLocation.Manual, canResize: false)) { var secondaryWindow = GetWindow("SecondaryWindow"); - var (_, _, zoomButton) = secondaryWindow.GetChromeButtons(); + var zoomButton = secondaryWindow.GetChromeButtons().Maximize; Assert.False(zoomButton.Enabled); } }