Skip to content

Commit

Permalink
Add system tests and try them in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jan 2, 2025
1 parent 4f3d0f4 commit b966481
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
test:
runs-on: windows-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
needs: build

steps:
- uses: actions/checkout@v4
Expand All @@ -71,5 +72,20 @@ jobs:
cp .env.example .env
dotnet restore src\WinDynamicDesktop.sln
- run: dotnet test --verbosity normal
- name: Unit Tests
run: dotnet test --filter type!=system --verbosity normal
working-directory: test

- run: |
npm install -g appium
Start-Process -NoNewWindow -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
working-directory: test
64 changes: 64 additions & 0 deletions test/SystemTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Win32;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;

namespace WinDynamicDesktop.Tests
{
public class SystemTests : IDisposable
{
private const string AppiumServerUrl = "http://127.0.0.1:4723";
private readonly string AppPath = Path.GetFullPath(@"..\..\..\bin\WinDynamicDesktop.exe");
private readonly WindowsDriver<WindowsElement> driver;

public SystemTests()
{
var appCapabilities = new AppiumOptions();
appCapabilities.AddAdditionalCapability("app", AppPath);
appCapabilities.AddAdditionalCapability("platformName", "Windows");
appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
driver = new WindowsDriver<WindowsElement>(new Uri(AppiumServerUrl), appCapabilities);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
}

[Fact, Trait("type", "system")]
public void ShouldUpdateWallpaper()
{
driver.FindElementByXPath("//Window[@Name='Select Language']").Click();
driver.FindElementByXPath("//Button[@Name='OK']").Click();
Thread.Sleep(TimeSpan.FromSeconds(1));

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();
driver.SwitchTo().Window(driver.WindowHandles.Last());
driver.FindElementByXPath("//Button[@Name='Yes']").Click();
Thread.Sleep(TimeSpan.FromSeconds(1));

driver.SwitchTo().Window(driver.WindowHandles[0]);
driver.FindElementByXPath("//Window[@Name='Select Theme']").Click();
driver.FindElementByAccessibilityId("listView1").SendKeys(Keys.Control + Keys.End);
driver.FindElementByXPath("//ListItem[@Name='Windows 11']").Click();
driver.FindElementByXPath("//Button[@Name='Apply']").Click();

Assert.Contains(["scripts", "settings.json", "themes"],
Directory.GetFileSystemEntries(Path.GetDirectoryName(AppPath)).Select(Path.GetFileName).ToArray());
Assert.StartsWith(Path.Combine(Path.GetDirectoryName(AppPath), "themes", "Windows_11", "img"), GetWallpaperPath());
}

public void Dispose()
{
driver?.Quit();
}

private string? GetWallpaperPath()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop"))
{
return key?.GetValue("WallPaper") as string;
}
}
}
}
1 change: 1 addition & 0 deletions test/WinDynamicDesktop.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.4.5" />
<PackageReference Include="FakeLocalTimeZone" Version="0.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand Down

0 comments on commit b966481

Please sign in to comment.