Skip to content

Commit b966481

Browse files
committed
Add system tests and try them in CI
1 parent 4f3d0f4 commit b966481

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
test:
6060
runs-on: windows-latest
6161
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
62+
needs: build
6263

6364
steps:
6465
- uses: actions/checkout@v4
@@ -71,5 +72,20 @@ jobs:
7172
cp .env.example .env
7273
dotnet restore src\WinDynamicDesktop.sln
7374
74-
- run: dotnet test --verbosity normal
75+
- name: Unit Tests
76+
run: dotnet test --filter type!=system --verbosity normal
77+
working-directory: test
78+
79+
- run: |
80+
npm install -g appium
81+
Start-Process -NoNewWindow -FilePath "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"
82+
Start-Sleep -Seconds 5
83+
84+
- uses: actions/download-artifact@v4
85+
with:
86+
name: exe-x64
87+
path: test\bin
88+
89+
- name: System Tests
90+
run: dotnet test --filter type=system --verbosity normal
7591
working-directory: test

test/SystemTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Microsoft.Win32;
2+
using OpenQA.Selenium;
3+
using OpenQA.Selenium.Appium;
4+
using OpenQA.Selenium.Appium.Windows;
5+
6+
namespace WinDynamicDesktop.Tests
7+
{
8+
public class SystemTests : IDisposable
9+
{
10+
private const string AppiumServerUrl = "http://127.0.0.1:4723";
11+
private readonly string AppPath = Path.GetFullPath(@"..\..\..\bin\WinDynamicDesktop.exe");
12+
private readonly WindowsDriver<WindowsElement> driver;
13+
14+
public SystemTests()
15+
{
16+
var appCapabilities = new AppiumOptions();
17+
appCapabilities.AddAdditionalCapability("app", AppPath);
18+
appCapabilities.AddAdditionalCapability("platformName", "Windows");
19+
appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
20+
driver = new WindowsDriver<WindowsElement>(new Uri(AppiumServerUrl), appCapabilities);
21+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
22+
}
23+
24+
[Fact, Trait("type", "system")]
25+
public void ShouldUpdateWallpaper()
26+
{
27+
driver.FindElementByXPath("//Window[@Name='Select Language']").Click();
28+
driver.FindElementByXPath("//Button[@Name='OK']").Click();
29+
Thread.Sleep(TimeSpan.FromSeconds(1));
30+
31+
driver.SwitchTo().Window(driver.WindowHandles[0]);
32+
driver.FindElementByXPath("//Window[@Name='Configure Schedule']").Click();
33+
driver.FindElementByAccessibilityId("radioButton1").Click();
34+
driver.FindElementByAccessibilityId("locationBox").SendKeys("New York NY");
35+
driver.FindElementByXPath("//Button[@Name='OK']").Click();
36+
driver.SwitchTo().Window(driver.WindowHandles.Last());
37+
driver.FindElementByXPath("//Button[@Name='Yes']").Click();
38+
Thread.Sleep(TimeSpan.FromSeconds(1));
39+
40+
driver.SwitchTo().Window(driver.WindowHandles[0]);
41+
driver.FindElementByXPath("//Window[@Name='Select Theme']").Click();
42+
driver.FindElementByAccessibilityId("listView1").SendKeys(Keys.Control + Keys.End);
43+
driver.FindElementByXPath("//ListItem[@Name='Windows 11']").Click();
44+
driver.FindElementByXPath("//Button[@Name='Apply']").Click();
45+
46+
Assert.Contains(["scripts", "settings.json", "themes"],
47+
Directory.GetFileSystemEntries(Path.GetDirectoryName(AppPath)).Select(Path.GetFileName).ToArray());
48+
Assert.StartsWith(Path.Combine(Path.GetDirectoryName(AppPath), "themes", "Windows_11", "img"), GetWallpaperPath());
49+
}
50+
51+
public void Dispose()
52+
{
53+
driver?.Quit();
54+
}
55+
56+
private string? GetWallpaperPath()
57+
{
58+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop"))
59+
{
60+
return key?.GetValue("WallPaper") as string;
61+
}
62+
}
63+
}
64+
}

test/WinDynamicDesktop.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="Appium.WebDriver" Version="4.4.5" />
1314
<PackageReference Include="FakeLocalTimeZone" Version="0.0.3" />
1415
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1516
<PackageReference Include="xunit" Version="2.9.2" />

0 commit comments

Comments
 (0)