Skip to content

Commit

Permalink
Enable automated UI tests for local runs (microsoft#2748)
Browse files Browse the repository at this point in the history
* Enable UI tests to be run locally

* fix up scripts

* update TODO text
  • Loading branch information
EricJohnson327 committed Apr 26, 2024
1 parent a21a3d0 commit aca7c20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
25 changes: 18 additions & 7 deletions Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ param (
[string]$Platform = "x64",
[string]$Configuration = "debug",
[switch]$IsAzurePipelineBuild = $false,
[switch]$RunUITests = $false,
[switch]$Help = $false
)

Expand Down Expand Up @@ -49,6 +50,8 @@ $isInstalled = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVe
if (-not $IsAzurePipelineBuild) {
if ($isInstalled) {
Write-Host "WinAppDriver is already installed on this computer."

Start-Process -FilePath "C:\Program Files\Windows Application Driver\WinAppDriver.exe"
} else {
Write-Host "WinAppDriver will be installed in the background."
$url = "https://github.com/microsoft/WinAppDriver/releases/download/v1.2.99/WindowsApplicationDriver-1.2.99-win-x64.exe"
Expand All @@ -62,8 +65,6 @@ if (-not $IsAzurePipelineBuild) {

Start-Process -Wait -FilePath (Join-Path $env:Build_SourcesDirectory "temp\WinAppDriverx64.exe") -ArgumentList "/S" -PassThru
}

Start-Process -FilePath "C:\Program Files\Windows Application Driver\WinAppDriver.exe"
}

function ShutDownTests {
Expand All @@ -89,15 +90,23 @@ if (-not (Test-Path -Path "AppxPackages")) {
try {
foreach ($platform in $env:Build_Platform.Split(",")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
# TODO: UI tests are currently disabled in the pipeline until signing is solved
if (-not $IsAzurePipelineBuild) {
# TODO: UI tests are currently disabled in the pipeline until we can run tests as user
if ($RunUITests) {
$DevHomePackage = Get-AppPackage "Microsoft.DevHome" -ErrorAction SilentlyContinue
if ($DevHomePackage) {
Write-Host "Uninstalling old Dev Home"
Remove-AppPackage -Package $DevHomePackage.PackageFullName
}
Write-Host "Installing Dev Home"
Add-AppPackage (Join-Path "AppxPackages" "$configuration\DevHome-$platform.msix")

if ($true) {
# Start/stop the app once so that WinAppDriver doesn't time out during first time setup
# and wait 60 seconds to give plenty of time
Start-Process "Shell:AppsFolder\Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App"
Start-Sleep 60
Stop-Process -Name "DevHome"
}
}

$vstestArgs = @(
Expand All @@ -108,12 +117,13 @@ try {
$winAppTestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=DevHome.UITest-$platform-$configuration.trx",
"/Settings:uitest\Test.runsettings",
"uitest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\DevHome.UITest.dll"
)

& $vstestPath $vstestArgs
# TODO: UI tests are currently disabled in the pipeline until signing is solved
if (-not $IsAzurePipelineBuild) {
# TODO: UI tests are currently disabled in the pipeline until we can run tests as user
if ($RunUITests) {
& $vstestPath $winAppTestArgs
}

Expand All @@ -128,12 +138,13 @@ try {
$winAppTestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=$tool.UITest-$platform-$configuration.trx",
"/Settings:uitest\Test.runsettings",
"tools\$tool\*UITest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\*.UITest.dll"
)

& $vstestPath $vstestArgs
# TODO: UI tests are currently disabled in the pipeline until signing is solved
if (-not $IsAzurePipelineBuild) {
if ($RunUITests) {
& $vstestPath $winAppTestArgs
}
}
Expand Down
23 changes: 1 addition & 22 deletions uitest/Dialogs/AddWidgetDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,7 @@ public AddWidgetDialog(WindowsDriver<WindowsElement> driver, DashboardPage dashb

public DashboardPage.WidgetControl AddCPUUsageWidget() => QuickAddWidget(CPUUsageNavigationItem, "CPU");

public DashboardPage.WidgetControl AddSSHWidget(string configFilePath)
{
return WaitForWidgetToBeAdded(() =>
{
Trace.WriteLine($"Clicking on SSH navigation item");
SSHNavigationItem.Click();
// Wait for the widget to be rendered before configuring and
// pinning it
// TODO: Can we use AccessibilityId for adaptive cards forms?
Trace.WriteLine($"Configuring SSH widget: Adding SSH config file path");
var container = Driver.WaitUntilVisible(ByWindowsAutomation.ClassName("NamedContainerAutomationPeer"));
var input = container.FindElementByClassName("TextBox");
input.Clear();
input.SendKeys(configFilePath);
var submit = container.FindElementByClassName("Button");
submit.Click();
Trace.WriteLine($"Pinning SSH widget");
PinButton.Click();
});
}
public DashboardPage.WidgetControl AddSSHWidget() => QuickAddWidget(SSHNavigationItem, "SSH keychain");

private string GetWidgetNavigationItemId(string widgetId) => $"NavViewItem_{Configuration.Widget.IdPrefix}!App!!{Configuration.Widget.Provider}!!{widgetId}";

Expand Down
2 changes: 1 addition & 1 deletion uitest/WidgetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void AddWidgetsTest(string[] widgetTitles)
["CPU"] = dialog => dialog.AddCPUUsageWidget(),
["Network"] = dialog => dialog.AddNetworkUsageWidget(),
["Memory"] = dialog => dialog.AddMemoryWidget(),
["SSH keychain"] = dialog => dialog.AddSSHWidget(GetTestAssetPath(@"Widgets\EmptySSHConfig")),
["SSH keychain"] = dialog => dialog.AddSSHWidget(),
};
var dashboard = Application.NavigateToDashboardPage();
dashboard.RemoveAllWidgets();
Expand Down

0 comments on commit aca7c20

Please sign in to comment.