From d413fbbb8e8b598c32f06e6288f3f311332adcf8 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 22 Oct 2022 00:36:25 +0200 Subject: [PATCH] Handle fullscreen windows better on mac. --- .../ElementExtensions.cs | 17 ++++++++++++----- .../WindowTests.cs | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs b/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs index 4b361c6716..e7837a6971 100644 --- a/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs +++ b/tests/Avalonia.IntegrationTests.Appium/ElementExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Disposables; using System.Runtime.InteropServices; +using System.Threading; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Interactions; @@ -110,24 +111,30 @@ namespace Avalonia.IntegrationTests.Appium { var oldWindows = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")); var oldWindowTitles = oldWindows.ToDictionary(x => x.Text); - + element.Click(); + + // Wait for animations to run. + Thread.Sleep(1000); var newWindows = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")); var newWindowTitles = newWindows.ToDictionary(x => x.Text); var newWindowTitle = Assert.Single(newWindowTitles.Keys.Except(oldWindowTitles.Keys)); - var newWindow = (AppiumWebElement)newWindowTitles[newWindowTitle]; - + return Disposable.Create(() => { // TODO: We should be able to use Cmd+W here but Avalonia apps don't seem to have this shortcut // set up by default. - var (close, _, _) = newWindow.GetChromeButtons(); + var windows = session.FindElements(By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")); + 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(); close!.Click(); }); } } - + public static void SendClick(this AppiumWebElement element) { // The Click() method seems to correspond to accessibilityPerformPress on macOS but certain controls diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs index b14c1f6cf3..9f542c75e2 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs @@ -89,6 +89,11 @@ namespace Avalonia.IntegrationTests.Appium { _session.FindElementByAccessibilityId("WindowState").SendClick(); _session.FindElementByName("Normal").SendClick(); + + // Wait for animations to run. + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + Thread.Sleep(1000); + } catch { /* Ignore errors in cleanup */ } } }