Skip to content

Commit c27e15b

Browse files
committed
Fix location prompt blocking system tests
1 parent 5c07a8b commit c27e15b

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,18 @@ jobs:
7979
- run: |
8080
npm install -g appium
8181
Start-Process -FilePath "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"
82-
Start-Sleep -Seconds 5
8382
8483
- uses: actions/download-artifact@v4
8584
with:
8685
name: exe-x64
8786
path: test\bin
8887

8988
- name: System Tests
90-
run: dotnet test --filter type=system --verbosity normal
89+
run: dotnet test --filter type=system --verbosity detailed
9190
working-directory: test
91+
92+
- uses: actions/upload-artifact@v4
93+
if: ${{ failure() }}
94+
with:
95+
name: test-dir
96+
path: test\bin

src/UwpLocation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public static async Task<bool> UpdateGeoposition()
6969

7070
return true;
7171
}
72-
catch (Exception exc) {
72+
catch (Exception exc)
73+
{
7374
lastUpdateError = exc;
7475
}
7576

test/SystemTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using OpenQA.Selenium;
33
using OpenQA.Selenium.Appium;
44
using OpenQA.Selenium.Appium.Windows;
5+
using System.Windows.Automation;
56

67
namespace WinDynamicDesktop.Tests
78
{
@@ -28,13 +29,13 @@ public void ShouldUpdateWallpaper()
2829
driver.FindElementByXPath("//Button[@Name='OK']").Click();
2930
Thread.Sleep(TimeSpan.FromSeconds(5));
3031

32+
if (HandleLocationPrompt()) Thread.Sleep(TimeSpan.FromSeconds(2));
3133
driver.SwitchTo().Window(driver.WindowHandles[0]);
3234
driver.FindElementByXPath("//Window[@Name='Configure Schedule']").Click();
3335
driver.FindElementByAccessibilityId("radioButton1").Click();
3436
driver.FindElementByAccessibilityId("locationBox").SendKeys("New York NY");
3537
driver.FindElementByXPath("//Button[@Name='OK']").Click();
3638
Thread.Sleep(TimeSpan.FromSeconds(2));
37-
driver.SwitchTo().Window(driver.WindowHandles.Last());
3839
driver.FindElementByXPath("//Button[@Name='Yes']").Click();
3940
Thread.Sleep(TimeSpan.FromSeconds(5));
4041

@@ -43,6 +44,7 @@ public void ShouldUpdateWallpaper()
4344
driver.FindElementByAccessibilityId("listView1").SendKeys(Keys.Control + Keys.End);
4445
driver.FindElementByXPath("//ListItem[@Name='Windows 11']").Click();
4546
driver.FindElementByXPath("//Button[@Name='Apply']").Click();
47+
Thread.Sleep(TimeSpan.FromSeconds(2));
4648

4749
Assert.Contains(["scripts", "settings.json", "themes"],
4850
Directory.GetFileSystemEntries(Path.GetDirectoryName(AppPath)).Select(Path.GetFileName).ToArray());
@@ -54,6 +56,20 @@ public void Dispose()
5456
driver?.Quit();
5557
}
5658

59+
private bool HandleLocationPrompt()
60+
{
61+
var dialogMatcher = new PropertyCondition(AutomationElement.NameProperty, "Let Windows and apps access your location?");
62+
var buttonMatcher = new PropertyCondition(AutomationElement.NameProperty, "Yes");
63+
AutomationElement dialog = AutomationElement.RootElement.FindFirst(TreeScope.Children, dialogMatcher);
64+
if (dialog?.FindFirst(TreeScope.Descendants, buttonMatcher) is AutomationElement yesButton &&
65+
yesButton.GetCurrentPattern(InvokePattern.Pattern) is InvokePattern invokePattern)
66+
{
67+
invokePattern.Invoke();
68+
return true;
69+
}
70+
return false;
71+
}
72+
5773
private string? GetWallpaperPath()
5874
{
5975
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop"))

0 commit comments

Comments
 (0)