Skip to content

Commit

Permalink
Fix location prompt blocking system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jan 6, 2025
1 parent 5c07a8b commit c27e15b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ 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:
name: exe-x64
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
3 changes: 2 additions & 1 deletion src/UwpLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static async Task<bool> UpdateGeoposition()

return true;
}
catch (Exception exc) {
catch (Exception exc)
{
lastUpdateError = exc;
}

Expand Down
18 changes: 17 additions & 1 deletion test/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System.Windows.Automation;

namespace WinDynamicDesktop.Tests
{
Expand All @@ -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));

Expand All @@ -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());
Expand All @@ -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"))
Expand Down

0 comments on commit c27e15b

Please sign in to comment.