Browse Source

Look up chrome buttons by a11y id.

XPath is slower, and unnecessary here.
pull/10677/head
Steven Kirk 3 years ago
parent
commit
2cce1d4d78
  1. 18
      tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs
  2. 31
      tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

18
tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs

@ -12,9 +12,10 @@ using Xunit;
namespace Avalonia.IntegrationTests.Appium namespace Avalonia.IntegrationTests.Appium
{ {
public record class WindowChrome( public record class WindowChrome(
AppiumWebElement Close, AppiumWebElement? Close,
AppiumWebElement Minimize, AppiumWebElement? Minimize,
AppiumWebElement Maximize); AppiumWebElement? Maximize,
AppiumWebElement? FullScreen);
internal static class ElementExtensions internal static class ElementExtensions
{ {
@ -25,10 +26,11 @@ namespace Avalonia.IntegrationTests.Appium
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{ {
var closeButton = window.FindElementByXPath("//XCUIElementTypeButton[1]"); var closeButton = window.FindElementsByAccessibilityId("_XCUI:CloseWindow").FirstOrDefault();
var fullscreenButton = window.FindElementByXPath("//XCUIElementTypeButton[2]"); var fullscreenButton = window.FindElementsByAccessibilityId("_XCUI:FullScreenWindow").FirstOrDefault();
var minimizeButton = window.FindElementByXPath("//XCUIElementTypeButton[3]"); var minimizeButton = window.FindElementsByAccessibilityId("_XCUI:MinimizeWindow").FirstOrDefault();
return new(closeButton, minimizeButton, fullscreenButton); var zoomButton = window.FindElementsByAccessibilityId("_XCUI:ZoomWindow").FirstOrDefault();
return new(closeButton, minimizeButton, zoomButton, fullscreenButton);
} }
throw new NotSupportedException("GetChromeButtons not supported on this platform."); throw new NotSupportedException("GetChromeButtons not supported on this platform.");
@ -143,7 +145,7 @@ namespace Avalonia.IntegrationTests.Appium
var text = windows.Select(x => x.Text).ToList(); var text = windows.Select(x => x.Text).ToList();
var newWindow = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")) var newWindow = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow"))
.First(x => x.Text == newWindowTitle); .First(x => x.Text == newWindowTitle);
var (close, _, _) = ((AppiumWebElement)newWindow).GetChromeButtons(); var close = ((AppiumWebElement)newWindow).GetChromeButtons().Close;
close!.Click(); close!.Click();
Thread.Sleep(1000); Thread.Sleep(1000);
}); });

31
tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

@ -85,7 +85,7 @@ namespace Avalonia.IntegrationTests.Appium
var mainWindow = GetWindow("MainWindow"); var mainWindow = GetWindow("MainWindow");
var buttons = mainWindow.GetChromeButtons(); var buttons = mainWindow.GetChromeButtons();
buttons.Maximize.Click(); buttons.FullScreen.Click();
Thread.Sleep(500); Thread.Sleep(500);
@ -239,17 +239,18 @@ namespace Avalonia.IntegrationTests.Appium
public void Parent_Window_Has_Disabled_ChromeButtons_When_Modal_Dialog_Shown() public void Parent_Window_Has_Disabled_ChromeButtons_When_Modal_Dialog_Shown()
{ {
var window = GetWindow("MainWindow"); var window = GetWindow("MainWindow");
var (closeButton, miniaturizeButton, zoomButton) = window.GetChromeButtons(); var windowChrome = window.GetChromeButtons();
Assert.True(closeButton.Enabled); Assert.True(windowChrome.Close.Enabled);
Assert.True(zoomButton.Enabled); Assert.True(windowChrome.Maximize.Enabled);
Assert.True(miniaturizeButton.Enabled); Assert.True(windowChrome.Maximize.Enabled);
Assert.Null(windowChrome.FullScreen.Enabled);
using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner)) using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner))
{ {
Assert.False(closeButton.Enabled); Assert.False(windowChrome.Close.Enabled);
Assert.False(zoomButton.Enabled); Assert.False(windowChrome.Maximize.Enabled);
Assert.False(miniaturizeButton.Enabled); Assert.False(windowChrome.Minimize.Enabled);
} }
} }
@ -259,11 +260,11 @@ namespace Avalonia.IntegrationTests.Appium
using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner)) using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.CenterOwner))
{ {
var secondaryWindow = GetWindow("SecondaryWindow"); var secondaryWindow = GetWindow("SecondaryWindow");
var (closeButton, miniaturizeButton, zoomButton) = secondaryWindow.GetChromeButtons(); var windowChrome = secondaryWindow.GetChromeButtons();
Assert.True(closeButton.Enabled); Assert.True(windowChrome.Close.Enabled);
Assert.True(zoomButton.Enabled); Assert.True(windowChrome.Maximize.Enabled);
Assert.False(miniaturizeButton.Enabled); Assert.False(windowChrome.Minimize.Enabled);
} }
} }
@ -274,7 +275,7 @@ namespace Avalonia.IntegrationTests.Appium
using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual)) using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual))
{ {
var secondaryWindow = GetWindow("SecondaryWindow"); var secondaryWindow = GetWindow("SecondaryWindow");
var (_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons(); var miniaturizeButton = secondaryWindow.GetChromeButtons().Minimize;
Assert.False(miniaturizeButton.Enabled); Assert.False(miniaturizeButton.Enabled);
} }
@ -288,7 +289,7 @@ namespace Avalonia.IntegrationTests.Appium
using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual)) using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual))
{ {
var secondaryWindow = GetWindow("SecondaryWindow"); var secondaryWindow = GetWindow("SecondaryWindow");
var (_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons(); var miniaturizeButton = secondaryWindow.GetChromeButtons().Minimize;
miniaturizeButton.Click(); miniaturizeButton.Click();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -344,7 +345,7 @@ namespace Avalonia.IntegrationTests.Appium
using (OpenWindow(null, mode, WindowStartupLocation.Manual, canResize: false)) using (OpenWindow(null, mode, WindowStartupLocation.Manual, canResize: false))
{ {
var secondaryWindow = GetWindow("SecondaryWindow"); var secondaryWindow = GetWindow("SecondaryWindow");
var (_, _, zoomButton) = secondaryWindow.GetChromeButtons(); var zoomButton = secondaryWindow.GetChromeButtons().Maximize;
Assert.False(zoomButton.Enabled); Assert.False(zoomButton.Enabled);
} }
} }

Loading…
Cancel
Save