From c21caa727b458e6526799b8c9244e5cbb281e20e Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Sat, 17 Aug 2024 14:15:16 +0200 Subject: [PATCH] UITest/InfoMan: add AboutTest --- .../InformationManager.Test.csproj | 19 +++++++++ .../Tests/GeneralTest.cs | 27 ++++++++++++ .../InformationManager.Test/UITest.cs | 41 +++++++++++++++++++ .../Views/ShellWindow.cs | 11 +++++ src/Samples.UITest/Samples.UITest.sln | 10 ++++- .../InformationManager/Assembler/App.xaml.cs | 9 ++-- .../Views/ShellWindow.xaml | 4 +- 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 src/Samples.UITest/InformationManager.Test/InformationManager.Test.csproj create mode 100644 src/Samples.UITest/InformationManager.Test/Tests/GeneralTest.cs create mode 100644 src/Samples.UITest/InformationManager.Test/UITest.cs create mode 100644 src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs diff --git a/src/Samples.UITest/InformationManager.Test/InformationManager.Test.csproj b/src/Samples.UITest/InformationManager.Test/InformationManager.Test.csproj new file mode 100644 index 00000000..37552950 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/InformationManager.Test.csproj @@ -0,0 +1,19 @@ + + + net8.0-windows + UITest.InformationManager + + enable + enable + + + + + + + + + + + + diff --git a/src/Samples.UITest/InformationManager.Test/Tests/GeneralTest.cs b/src/Samples.UITest/InformationManager.Test/Tests/GeneralTest.cs new file mode 100644 index 00000000..36e5cc51 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Tests/GeneralTest.cs @@ -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(); + 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(); + }); +} diff --git a/src/Samples.UITest/InformationManager.Test/UITest.cs b/src/Samples.UITest/InformationManager.Test/UITest.cs new file mode 100644 index 00000000..ce3d5b4e --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/UITest.cs @@ -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(); +} + +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))); + } +} \ No newline at end of file diff --git a/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs b/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs new file mode 100644 index 00000000..b0c76754 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs @@ -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(); +} diff --git a/src/Samples.UITest/Samples.UITest.sln b/src/Samples.UITest/Samples.UITest.sln index cb64ab9f..3b467a48 100644 --- a/src/Samples.UITest/Samples.UITest.sln +++ b/src/Samples.UITest/Samples.UITest.sln @@ -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 @@ -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 diff --git a/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs b/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs index ce94488b..0ca28bf0 100644 --- a/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs +++ b/src/System.Waf/Samples/InformationManager/Assembler/App.xaml.cs @@ -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; @@ -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(); foreach (var x in presentationServices) x.Initialize(); - // Initialize and run all module controllers moduleControllers = container.GetExportedValues(); foreach (var x in moduleControllers) x.Initialize(); foreach (var x in moduleControllers) x.Run(); diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml index 132a73ae..79ae8ece 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Presentation/Views/ShellWindow.xaml @@ -24,8 +24,8 @@ - - + +