Skip to content

Commit 676122d

Browse files
committed
test(e2e): automate the launch of the Backend. Now e2e tests are fully automated.
1 parent 37416a2 commit 676122d

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

Desktop.Tests/e2e/AppActions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
using System;
22
using Desktop.Tests.e2e.Drivers;
3+
using Desktop.Tests.e2e.Utils;
34

45
namespace Desktop.Tests.e2e;
56

67
public class AppActions : IDisposable
78
{
8-
private readonly MainWindowDriver mainWindow = new();
9+
private readonly MainWindowDriver mainWindow;
10+
private readonly BackendLauncher backendLauncher;
11+
12+
public AppActions()
13+
{
14+
backendLauncher = new BackendLauncher();
15+
backendLauncher.Launch();
16+
17+
mainWindow = new MainWindowDriver();
18+
}
919

1020
public void Dispose()
1121
{
22+
backendLauncher.Dispose();
1223
mainWindow.Dispose();
1324
}
1425

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
5+
namespace Desktop.Tests.e2e.Utils;
6+
7+
public class BackendLauncher : IDisposable
8+
{
9+
private Process process;
10+
11+
/// <remarks>
12+
/// This is a tentative approach. It is error-prone, fragile and couples both
13+
/// the location of the Backend and its execution to the same machine that the
14+
/// Desktop app is running for the test.
15+
/// <para>
16+
/// Ideally, the desired version of the Backend to test will be deployed in
17+
/// a Docker container by the CI/CD pipeline, running health checks and
18+
/// ensuring it is reachable for this e2e tests.
19+
/// </para>
20+
/// </remarks>
21+
public void Launch()
22+
{
23+
var pathToBackend = Path.GetFullPath(
24+
Path.Combine(
25+
Environment.CurrentDirectory,
26+
"..",
27+
"..",
28+
"..",
29+
"..",
30+
"Backend",
31+
"Backend",
32+
"Backend.csproj"));
33+
34+
var startInfo = new ProcessStartInfo
35+
{
36+
FileName = "dotnet",
37+
Arguments =
38+
$"run --project {pathToBackend} --applicationUrl http://localhost:5045",
39+
RedirectStandardOutput = true,
40+
RedirectStandardError = true,
41+
UseShellExecute = false,
42+
CreateNoWindow = true
43+
};
44+
process = Process.Start(startInfo);
45+
}
46+
47+
public void Dispose()
48+
{
49+
process.Kill();
50+
}
51+
}

0 commit comments

Comments
 (0)