-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests) E2E launch tests to protect the Windows desktop app
- Loading branch information
Showing
7 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using NUnit.Framework; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using FlaUI.Core.AutomationElements; | ||
using FlaUI.Core.Definitions; | ||
using FlaUI.Core.Tools; | ||
using FlaUI.UIA3; | ||
using System.Diagnostics; | ||
using System.Linq.Expressions; | ||
using System.Windows.Forms; | ||
namespace Rnwood.Smtp4dev.Desktop.Tests | ||
{ | ||
public class Tests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
[Test] | ||
public void LaunchAndCheckUILoaded() | ||
{ | ||
string workingDir = Environment.GetEnvironmentVariable("SMTP4DEV_E2E_WORKINGDIR"); | ||
string binary = Environment.GetEnvironmentVariable("SMTP4DEV_E2E_BINARY"); | ||
|
||
|
||
using FlaUI.Core.Application app = FlaUI.Core.Application.Launch(new ProcessStartInfo(binary, "--smtpport=0") { WorkingDirectory = workingDir }); | ||
using var automation = new UIA3Automation(); | ||
|
||
app.WaitWhileMainHandleIsMissing(); | ||
var window = app.GetMainWindow(automation); | ||
window.Move(0, 0); | ||
|
||
|
||
try | ||
{ | ||
|
||
Retry.WhileException(() => | ||
{ | ||
app.WaitWhileBusy(); | ||
window = app.GetMainWindow(automation); | ||
var element = window.FindFirstDescendant(f => f.ByName("SMTP server", FlaUI.Core.Definitions.PropertyConditionFlags.MatchSubstring)) ?? | ||
throw new Exception( "Did not find status label"); | ||
var text = element.AsButton().Name; | ||
if (!text.Contains("listening on port")) | ||
throw new Exception("Server not listening: " + text); | ||
}, TimeSpan.FromSeconds(30), null, true); | ||
|
||
} finally | ||
{ | ||
try | ||
{ | ||
string screenshotFileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, Guid.NewGuid() + ".png"); | ||
window.CaptureToFile(screenshotFileName); | ||
TestContext.AddTestAttachment(screenshotFileName); | ||
} catch (Exception e) | ||
{ | ||
TestContext.WriteLine($"Screenshot failed with exception: {e}"); | ||
} | ||
|
||
app.Close(); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Rnwood.Smtp4dev.Desktop.Tests/Rnwood.Smtp4dev.Desktop.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FlaUI.Core" Version="4.0.0" /> | ||
<PackageReference Include="FlaUI.UIA3" Version="4.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<RunConfiguration> | ||
<EnvironmentVariables> | ||
<SMTP4DEV_E2E_WORKINGDIR>C:\src\smtp4dev-master\Rnwood.Smtp4dev.Desktop\bin\Debug\net8.0</SMTP4DEV_E2E_WORKINGDIR> | ||
<SMTP4DEV_E2E_BINARY>C:\src\smtp4dev-master\Rnwood.Smtp4dev.Desktop\bin\Debug\net8.0\Rnwood.Smtp4dev.Desktop.exe</SMTP4DEV_E2E_BINARY> | ||
</EnvironmentVariables> | ||
</RunConfiguration> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters