Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pc 686 e2e nieuws werkinstructies #985

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions .github/workflows/playwright.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,8 @@ jobs:
'TestSettings:TEST_PASSWORD': '${{ secrets.PLAYWRIGHT_PASSWORD }}'
'TestSettings:TEST_TOTP_SECRET': ${{ secrets.PLAYWRIGHT_TOTP_SECRET }}
'TestSettings:TEST_BASE_URL': ${{ secrets.PLAYWRIGHT_BASE_URL }}
- name: Create html file
if: ${{ failure() && steps.e2e.conclusion == 'failure' }}
run: |
cd bin/Debug/net8.0/playwright-traces
my_string=$(echo *.zip)
IFS=' ' read -ra my_array <<< "$my_string"
result='<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Playwright traces</title></head><body><ul>'

#Print the split string
for i in "${my_array[@]}"
do
result+="<li><a target=\"_blank\" href=\"https://trace.playwright.dev/?trace=https://klantinteractie-servicesysteem.github.io/KISS-frontend/$i\">$i</a></li>"
done

result+="</ul></body></html>"
echo "$result"
echo "$result" > index.html
- name: Deploy to GitHub Pages
if: ${{ failure() && steps.e2e.conclusion == 'failure' }}
if: ${{ always() }}
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
19 changes: 19 additions & 0 deletions Kiss.Bff.EndToEndTest/Helpers/AcceptAllDialogs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Kiss.Bff.EndToEndTest.Helpers
{
public static class AcceptAllDialogsExtension
{
public static IDisposable AcceptAllDialogs(this IPage page)
{
page.Dialog += Accept;
return new DoOnDispose(() => page.Dialog -= Accept);
}

private static async void Accept(object? _, IDialog dialog) => await dialog.AcceptAsync();


private sealed class DoOnDispose(Action action) : IDisposable
{
public void Dispose() => action();
}
}
}
100 changes: 76 additions & 24 deletions Kiss.Bff.EndToEndTest/Infrastructure/BaseTestInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Extensions.Configuration;
using System.Collections.Concurrent;
using System.Drawing;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;


namespace Kiss.Bff.EndToEndTest
Expand All @@ -14,51 +17,90 @@ public class BaseTestInitializer : PageTest
.Build();

private static readonly UniqueOtpHelper s_uniqueOtpHelper = new(GetRequiredConfig("TestSettings:TEST_TOTP_SECRET"));
private static readonly ConcurrentDictionary<string, string> s_testsHtml = [];


private readonly List<string> _steps = [];

[TestInitialize]
public virtual async Task TestInitialize()
{
var username = GetRequiredConfig("TestSettings:TEST_USERNAME");
var password = GetRequiredConfig("TestSettings:TEST_PASSWORD");

var loginHelper = new AzureAdLoginHelper(Page, username, password, s_uniqueOtpHelper);
await loginHelper.LoginAsync();
await Context.StorageStateAsync(new() { Path = StoragePath });

await Context.Tracing.StartAsync(new()
{
Title = $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}",
Screenshots = true,
Snapshots = true,
Sources = true
Sources = true,
});

var loginHelper = new AzureAdLoginHelper(Page, username, password, s_uniqueOtpHelper);
await loginHelper.LoginAsync();
await Context.StorageStateAsync(new() { Path = StoragePath });
Console.WriteLine(TestContext.TestName);
}

protected async Task Step(string description)
{
await Context.Tracing.GroupEndAsync();
await Context.Tracing.GroupAsync(description);
Console.WriteLine(description);
_steps.Add(description);
}

[TestCleanup]
public async Task TestCleanup()
{
var options = TestContext.CurrentTestOutcome != UnitTestOutcome.Passed
? new TracingStopOptions
{
Path = Path.Combine(
Environment.CurrentDirectory,
"playwright-traces",
$"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip"
)
}
: null;

await Context.Tracing.StopAsync(options);
await Context.Tracing.GroupEndAsync();
var fileName = $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip";
var fullPath = Path.Combine(Environment.CurrentDirectory, "playwright-traces", fileName);

await Context.Tracing.StopAsync(new()
{
Path = fullPath
});

var html = $"""
<div data-outcome="{TestContext.CurrentTestOutcome}">
<h2>{TestContext.TestName}</h2>
<a target="_blank" href="https://trace.playwright.dev/?trace=https://klantinteractie-servicesysteem.github.io/KISS-frontend/{fileName}">Playwright tracing</a>
<p>Steps:</p>
<ol>{string.Join("", _steps.Select(step => $"""
<li>{step}</li>
"""))}
</ol>
</div>
""";

s_testsHtml.TryAdd(TestContext.TestName!, html);
}

public override BrowserNewContextOptions ContextOptions()
[ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass)]
public static async Task ClassCleanup()
{
return new(base.ContextOptions())
{
BaseURL = GetRequiredConfig("TestSettings:TEST_BASE_URL"),
// save auth state so we don't need to log in in every single test
StorageStatePath = File.Exists(StoragePath) ? StoragePath : null,
};
var html = $$"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src https://unpkg.com/[email protected]/simple.min.css 'sha256-kZS4Ytg58npMuRkQ/J+zM+WLW6n1befhcf5YgPVHdEE=';">
<title>Playwright traces</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/simple.min.css" integrity="sha384-Cxvt41nwdtHMOjpCqr+FaCybNL58LeIc0vPSLR4KlFSCBrHTb095iJbbw+hDTklQ" crossorigin="anonymous">
<style>[data-outcome=Failed]{color: var(--code)}</style>
</head>
<body>
<main>
{{string.Join("", s_testsHtml.OrderBy(x=> x.Key).Select(x=> x.Value))}}
</main>
</body>
""";

using var writer = File.CreateText(Path.Combine(Environment.CurrentDirectory, "playwright-traces", "index.html"));
await writer.WriteLineAsync(html);
}

private static string GetRequiredConfig(string key)
Expand All @@ -70,5 +112,15 @@ private static string GetRequiredConfig(string key)
}
return value;
}

public override BrowserNewContextOptions ContextOptions()
{
return new(base.ContextOptions())
{
BaseURL = GetRequiredConfig("TestSettings:TEST_BASE_URL"),
// save auth state so we don't need to log in in every single test
StorageStatePath = File.Exists(StoragePath) ? StoragePath : null,
};
}
}
}
14 changes: 7 additions & 7 deletions Kiss.Bff.EndToEndTest/Kiss.Bff.EndToEndTest.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -12,12 +12,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
<PackageReference Include="Microsoft.Playwright.MSTest" Version="1.45.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="Microsoft.Playwright.MSTest" Version="1.49.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading
Loading