Skip to content

Commit

Permalink
Fix not finding NSWindow in headless scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jfversluis committed Sep 7, 2023
1 parent 7ecc7eb commit 7bb24b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ static MauiTestApplicationDelegate()
{
EnvVars[envvar] = Environment.GetEnvironmentVariable(envvar);
}

// Add entry to indicate we're running headless
EnvVars.Add("headlessrunner", "true");
}

static void SetEnvironmentVariables()
Expand Down
10 changes: 10 additions & 0 deletions src/TestUtils/src/DeviceTests/AssertionExtensions.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CoreAnimation;
Expand Down Expand Up @@ -582,6 +583,15 @@ public static void AssertEqual(this CATransform3D expected, CATransform3D actual
{
foreach (var window in windowScene.Windows)
{
#if MACCATALYST
// When running headless (on CI or local) Mac Catalyst has trouble finding the window through the method below.
// Added an env variable to accommodate for this and just return the first window found.
File.AppendAllText("/Users/jfversluis/Desktop/foo.txt", "foo");
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("headlessrunner")))
{
return window;
}
#endif
if (window.IsKeyWindow)
{
return window;
Expand Down

0 comments on commit 7bb24b4

Please sign in to comment.