Skip to content

Commit

Permalink
UITest/InfoMan: add AboutTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Aug 17, 2024
1 parent 3485134 commit c21caa7
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>UITest.InformationManager</RootNamespace>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../UITest.Core/UITest.Core.csproj" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Tests/GeneralTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Capturing;
using UITest.SystemViews;
using Xunit;
using Xunit.Abstractions;

namespace UITest.InformationManager.Tests;

public class GeneralTest(ITestOutputHelper log) : UITest(log)
{
[Fact]
public void AboutTest() => Run(() =>
{
Launch();
var window = GetShellWindow();
window.AboutButton.Click();

var messageBox = window.FirstModalWindow().As<MessageBox>();
Assert.Equal("Waf Information Manager", messageBox.Title);
Log.WriteLine(messageBox.Message);
Assert.StartsWith("Waf Information Manager ", messageBox.Message);
Capture.Screen().ToFile(GetScreenshotFile("About"));
messageBox.Buttons[0].Click();

window.ExitButton.Click();
});
}
41 changes: 41 additions & 0 deletions src/Samples.UITest/InformationManager.Test/UITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using System.Diagnostics;
using UITest.InformationManager.Views;
using Xunit;
using Xunit.Abstractions;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

namespace UITest.InformationManager;

public abstract class UITest(ITestOutputHelper log) : UITestBase(log, "InformationManager.exe",
Environment.GetEnvironmentVariable("UITestExePath") ?? "out/InformationManager/Release/net8.0-windows/",
Environment.GetEnvironmentVariable("UITestOutputPath") ?? "out/Samples.UITest/InformationManager/")
{
public Application Launch(LaunchArguments? arguments = null, bool resetSettings = true)
{
Log.WriteLine("");
if (resetSettings)
{
var productName = FileVersionInfo.GetVersionInfo(Executable).ProductName ?? throw new InvalidOperationException("Could not read the ProductName from the exe.");
var settingsFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), productName, "Settings", "Settings.xml");
if (File.Exists(settingsFile)) File.Delete(settingsFile);
Log.WriteLine($"Delete settings: {settingsFile}");
}
var args = (arguments ?? new LaunchArguments()).ToArguments();
Log.WriteLine($"Launch: {args}");
return App = Application.Launch(Executable, args);
}

public ShellWindow GetShellWindow() => App!.GetMainWindow(Automation).As<ShellWindow>();
}

public record LaunchArguments(string? UICulture = "en-US", string? Culture = "en-US", string? AdditionalArguments = null) : LaunchArgumentsBase
{
public override string ToArguments()
{
string?[] args = [CreateArg(UICulture), CreateArg(Culture), AdditionalArguments];
return string.Join(" ", args.Where(x => !string.IsNullOrEmpty(x)));
}
}
11 changes: 11 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;

namespace UITest.InformationManager.Views;

public class ShellWindow(FrameworkAutomationElementBase element) : Window(element)
{
public Button AboutButton => this.Find("AboutButton").AsButton();

public Button ExitButton => this.Find("ExitButton").AsButton();
}
10 changes: 8 additions & 2 deletions src/Samples.UITest/Samples.UITest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Writer.Test", "Writer.Test\Writer.Test.csproj", "{8FBAB64A-51F5-40F8-8B56-4AEE7BE49838}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookLibrary.Test", "BookLibrary.Test\BookLibrary.Test.csproj", "{A239DB72-F7D9-4DE9-83F9-E0D852FA5F8F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookLibrary.Test", "BookLibrary.Test\BookLibrary.Test.csproj", "{A239DB72-F7D9-4DE9-83F9-E0D852FA5F8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITest.Core", "UITest.Core\UITest.Core.csproj", "{4B2174D9-B723-42AA-90DA-2F556409F19A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITest.Core", "UITest.Core\UITest.Core.csproj", "{4B2174D9-B723-42AA-90DA-2F556409F19A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InformationManager.Test", "InformationManager.Test\InformationManager.Test.csproj", "{18006BE9-7056-48FB-97CF-F7B25C43358B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{4B2174D9-B723-42AA-90DA-2F556409F19A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B2174D9-B723-42AA-90DA-2F556409F19A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B2174D9-B723-42AA-90DA-2F556409F19A}.Release|Any CPU.Build.0 = Release|Any CPU
{18006BE9-7056-48FB-97CF-F7B25C43358B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18006BE9-7056-48FB-97CF-F7B25C43358B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18006BE9-7056-48FB-97CF-F7B25C43358B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18006BE9-7056-48FB-97CF-F7B25C43358B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Globalization;
using System.IO;
using System.Waf.Applications;
using System.Waf.Applications.Services;
using System.Windows;
Expand Down Expand Up @@ -75,18 +76,20 @@ protected override void OnStartup(StartupEventArgs e)
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly)); // WinApplicationFramework

// Load module assemblies as well. See App.config file.
foreach (var x in Settings.Default.ModuleAssemblies) catalog.Catalogs.Add(new AssemblyCatalog(x));
var baseDir = AppContext.BaseDirectory;
foreach (var x in Settings.Default.ModuleAssemblies)
{
catalog.Catalogs.Add(new AssemblyCatalog(Path.Combine(baseDir, x!)));
}

container = new(catalog, CompositionOptions.DisableSilentRejection);
var batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);

// Initialize all presentation services
var presentationServices = container.GetExportedValues<IPresentationService>();
foreach (var x in presentationServices) x.Initialize();

// Initialize and run all module controllers
moduleControllers = container.GetExportedValues<IModuleController>();
foreach (var x in moduleControllers) x.Initialize();
foreach (var x in moduleControllers) x.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</Grid.RowDefinitions>

<ToolBar x:Name="toolBar" Grid.ColumnSpan="2" Grid.Row="0">
<Button Command="{Binding AboutCommand}" ToolTip="Shows the about dialog."><AccessText Text="_About"/></Button>
<Button Command="{Binding ExitCommand}" ToolTip="Close the application."><AccessText Text="E_xit"/></Button>
<Button Command="{Binding AboutCommand}" ToolTip="Shows the about dialog." AutomationProperties.AutomationId="AboutButton"><AccessText Text="_About"/></Button>
<Button Command="{Binding ExitCommand}" ToolTip="Close the application." AutomationProperties.AutomationId="ExitButton"><AccessText Text="E_xit"/></Button>
</ToolBar>

<TreeView x:Name="navigationView" Grid.Column="0" Grid.Row="1" BorderThickness="0" Margin="0,0,4,0">
Expand Down

0 comments on commit c21caa7

Please sign in to comment.