From c27e15b6987dd5d526508c77c514c189a131e9ca Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 6 Jan 2025 07:07:03 -0500 Subject: [PATCH] Fix location prompt blocking system tests --- .github/workflows/build.yml | 9 +++++++-- src/UwpLocation.cs | 3 ++- test/SystemTests.cs | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07da32b..e9d9517 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,7 +79,6 @@ jobs: - run: | npm install -g appium Start-Process -FilePath "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe" - Start-Sleep -Seconds 5 - uses: actions/download-artifact@v4 with: @@ -87,5 +86,11 @@ jobs: path: test\bin - name: System Tests - run: dotnet test --filter type=system --verbosity normal + run: dotnet test --filter type=system --verbosity detailed working-directory: test + + - uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: test-dir + path: test\bin diff --git a/src/UwpLocation.cs b/src/UwpLocation.cs index 2e42d6f..dc9241c 100644 --- a/src/UwpLocation.cs +++ b/src/UwpLocation.cs @@ -69,7 +69,8 @@ public static async Task UpdateGeoposition() return true; } - catch (Exception exc) { + catch (Exception exc) + { lastUpdateError = exc; } diff --git a/test/SystemTests.cs b/test/SystemTests.cs index 5d1b4f0..c55449e 100644 --- a/test/SystemTests.cs +++ b/test/SystemTests.cs @@ -2,6 +2,7 @@ using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; +using System.Windows.Automation; namespace WinDynamicDesktop.Tests { @@ -28,13 +29,13 @@ public void ShouldUpdateWallpaper() driver.FindElementByXPath("//Button[@Name='OK']").Click(); Thread.Sleep(TimeSpan.FromSeconds(5)); + if (HandleLocationPrompt()) Thread.Sleep(TimeSpan.FromSeconds(2)); driver.SwitchTo().Window(driver.WindowHandles[0]); driver.FindElementByXPath("//Window[@Name='Configure Schedule']").Click(); driver.FindElementByAccessibilityId("radioButton1").Click(); driver.FindElementByAccessibilityId("locationBox").SendKeys("New York NY"); driver.FindElementByXPath("//Button[@Name='OK']").Click(); Thread.Sleep(TimeSpan.FromSeconds(2)); - driver.SwitchTo().Window(driver.WindowHandles.Last()); driver.FindElementByXPath("//Button[@Name='Yes']").Click(); Thread.Sleep(TimeSpan.FromSeconds(5)); @@ -43,6 +44,7 @@ public void ShouldUpdateWallpaper() driver.FindElementByAccessibilityId("listView1").SendKeys(Keys.Control + Keys.End); driver.FindElementByXPath("//ListItem[@Name='Windows 11']").Click(); driver.FindElementByXPath("//Button[@Name='Apply']").Click(); + Thread.Sleep(TimeSpan.FromSeconds(2)); Assert.Contains(["scripts", "settings.json", "themes"], Directory.GetFileSystemEntries(Path.GetDirectoryName(AppPath)).Select(Path.GetFileName).ToArray()); @@ -54,6 +56,20 @@ public void Dispose() driver?.Quit(); } + private bool HandleLocationPrompt() + { + var dialogMatcher = new PropertyCondition(AutomationElement.NameProperty, "Let Windows and apps access your location?"); + var buttonMatcher = new PropertyCondition(AutomationElement.NameProperty, "Yes"); + AutomationElement dialog = AutomationElement.RootElement.FindFirst(TreeScope.Children, dialogMatcher); + if (dialog?.FindFirst(TreeScope.Descendants, buttonMatcher) is AutomationElement yesButton && + yesButton.GetCurrentPattern(InvokePattern.Pattern) is InvokePattern invokePattern) + { + invokePattern.Invoke(); + return true; + } + return false; + } + private string? GetWallpaperPath() { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop"))