Skip to content

Commit

Permalink
UITest: add first BookLibrary test; improve UITest infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed May 4, 2024
1 parent 79102b6 commit d70c445
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Samples.UITest/BookLibrary.Test/BookLibrary.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<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"/>
<ProjectReference Include="../UITest.Core/UITest.Core.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Xunit;
using Xunit.Abstractions;

namespace UITest.BookLibrary.Tests;

public class BookLibraryTest(ITestOutputHelper log) : UITest(log)
{
[Fact]
public void AboutTest()
{
Launch();
var window = GetShellWindow();
Thread.Sleep(3000);
}
}
28 changes: 28 additions & 0 deletions src/Samples.UITest/BookLibrary.Test/UITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using UITest.BookLibrary.Views;
using Xunit.Abstractions;

namespace UITest.BookLibrary;

public class UITest(ITestOutputHelper log) : UITestBase(log, "BookLibrary/Release/net8.0-windows/BookLibrary.exe", "Samples.UITest/BookLibrary/")
{
public Application Launch(LaunchArguments? arguments = null)
{
var args = (arguments ?? new LaunchArguments()).ToArguments();
Log.WriteLine($"Launch: {args}");
Environment.CurrentDirectory = Path.GetDirectoryName(Executable)!; // TODO: Bug in App that CurrentDir must be Exe dir
return App = Application.Launch(Executable, args);
}

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

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

namespace UITest.BookLibrary.Views;

public class ShellWindow(FrameworkAutomationElementBase element) : Window(element)
{
}
2 changes: 1 addition & 1 deletion src/Samples.UITest/UITest.Core/UITest.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

<ItemGroup>
<PackageReference Include="FlaUI.UIA3" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Samples.UITest/Writer.Test/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace UITest.Writer;

public class UITest(ITestOutputHelper log) : UITestBase(log, "Writer/Release/net8.0-windows/writer.exe", "Samples.UITest/Writer/")
public class UITest(ITestOutputHelper log) : UITestBase(log, "Writer/Release/net8.0-windows/Writer.exe", "Samples.UITest/Writer/")
{
public Application Launch(LaunchArguments? arguments = null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Samples.UITest/Writer.Test/Writer.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<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"/>
<ProjectReference Include="../UITest.Core/UITest.Core.csproj" />
</ItemGroup>
</Project>

0 comments on commit d70c445

Please sign in to comment.