Skip to content

Commit 5f51d4c

Browse files
committed
Initial Commit
0 parents  commit 5f51d4c

12 files changed

Lines changed: 584 additions & 0 deletions
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
name: Test & Report
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
testSuite:
7+
description: "Which tests to run"
8+
type: choice
9+
required: true
10+
default: smoke
11+
options:
12+
- smoke
13+
- regression
14+
- LoginPage
15+
- SecureArea
16+
17+
permissions:
18+
contents: write
19+
pages: write
20+
id-token: write
21+
22+
jobs:
23+
test_chromium:
24+
name: Run tests (Chromium)
25+
runs-on: ubuntu-latest
26+
27+
env:
28+
BROWSER: chromium
29+
30+
steps:
31+
- name: Checkout
32+
- uses: actions/checkout@v4
33+
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v4
36+
with:
37+
dotnet-version: "10.0.x"
38+
39+
- name: Restore
40+
run: dotnet restore Tests.csproj
41+
42+
- name: Build
43+
run: dotnet build Tests.csproj --configuration Release --no-restore
44+
45+
- name: Install Playwright browsers
46+
run: pwsh bin/Release/net10.0/playwright.ps1 install --with-deps
47+
48+
- name: Run tests (Chromium)
49+
env:
50+
TEST_SUITE: ${{ github.event.inputs.testSuite }}
51+
run: |
52+
if [ "$TEST_SUITE" = "smoke" ]; then
53+
FILTER='TestCategory=smoke'
54+
elif [ "$TEST_SUITE" = "regression" ]; then
55+
FILTER=''
56+
elif [ "$TEST_SUITE" = "LoginPage" ]; then
57+
FILTER='FullyQualifiedName~LoginPageTests'
58+
elif [ "$TEST_SUITE" = "SecureArea" ]; then
59+
FILTER='FullyQualifiedName~SecureAreaTests'
60+
else
61+
FILTER=''
62+
fi
63+
64+
if [ -z "$FILTER" ]; then
65+
dotnet test Tests.csproj --configuration Release
66+
else
67+
dotnet test Tests.csproj --configuration Release --filter "$FILTER"
68+
fi
69+
70+
- name: Upload Allure results (Chromium)
71+
if: always()
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: allure-results-chromium
75+
path: "**/allure-results"
76+
if-no-files-found: ignore
77+
78+
test_firefox:
79+
name: Run tests (Firefox)
80+
runs-on: ubuntu-latest
81+
82+
env:
83+
BROWSER: firefox
84+
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@v4
88+
89+
- name: Setup .NET
90+
uses: actions/setup-dotnet@v4
91+
with:
92+
dotnet-version: "10.0.x"
93+
94+
- name: Restore
95+
run: dotnet restore Tests.csproj
96+
97+
- name: Build
98+
run: dotnet build Tests.csproj --configuration Release --no-restore
99+
100+
- name: Install Playwright browsers
101+
run: pwsh bin/Release/net10.0/playwright.ps1 install --with-deps
102+
103+
- name: Run tests (Firefox)
104+
env:
105+
TEST_SUITE: ${{ github.event.inputs.testSuite }}
106+
run: |
107+
if [ "$TEST_SUITE" = "smoke" ]; then
108+
FILTER='TestCategory=smoke'
109+
elif [ "$TEST_SUITE" = "regression" ]; then
110+
FILTER=''
111+
elif [ "$TEST_SUITE" = "LoginPage" ]; then
112+
FILTER='FullyQualifiedName~LoginPageTests'
113+
elif [ "$TEST_SUITE" = "SecureArea" ]; then
114+
FILTER='FullyQualifiedName~SecureAreaTests'
115+
else
116+
FILTER=''
117+
fi
118+
119+
if [ -z "$FILTER" ]; then
120+
dotnet test Tests.csproj --configuration Release
121+
else
122+
dotnet test Tests.csproj --configuration Release --filter "$FILTER"
123+
fi
124+
125+
- name: Upload Allure results (Firefox)
126+
if: always()
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: allure-results-firefox
130+
path: "**/allure-results"
131+
if-no-files-found: ignore
132+
133+
test_webkit:
134+
name: Run tests (WebKit)
135+
runs-on: ubuntu-latest
136+
137+
env:
138+
BROWSER: webkit
139+
140+
steps:
141+
- name: Checkout
142+
uses: actions/checkout@v4
143+
144+
- name: Setup .NET
145+
uses: actions/setup-dotnet@v4
146+
with:
147+
dotnet-version: "10.0.x"
148+
149+
- name: Restore
150+
run: dotnet restore Tests.csproj
151+
152+
- name: Build
153+
run: dotnet build Tests.csproj --configuration Release --no-restore
154+
155+
- name: Install Playwright browsers
156+
run: pwsh bin/Release/net10.0/playwright.ps1 install --with-deps
157+
158+
- name: Run tests (WebKit)
159+
env:
160+
TEST_SUITE: ${{ github.event.inputs.testSuite }}
161+
run: |
162+
if [ "$TEST_SUITE" = "smoke" ]; then
163+
FILTER='TestCategory=smoke'
164+
elif [ "$TEST_SUITE" = "regression" ]; then
165+
FILTER=''
166+
elif [ "$TEST_SUITE" = "LoginPage" ]; then
167+
FILTER='FullyQualifiedName~LoginPageTests'
168+
elif [ "$TEST_SUITE" = "SecureArea" ]; then
169+
FILTER='FullyQualifiedName~SecureAreaTests'
170+
else
171+
FILTER=''
172+
fi
173+
174+
if [ -z "$FILTER" ]; then
175+
dotnet test Tests.csproj --configuration Release
176+
else
177+
dotnet test Tests.csproj --configuration Release --filter "$FILTER"
178+
fi
179+
180+
- name: Upload Allure results (WebKit)
181+
if: always()
182+
uses: actions/upload-artifact@v4
183+
with:
184+
name: allure-results-webkit
185+
path: "**/allure-results"
186+
if-no-files-found: ignore
187+
188+
report:
189+
name: Generate & Publish Allure report
190+
runs-on: ubuntu-latest
191+
needs:
192+
- test_chromium
193+
- test_firefox
194+
- test_webkit
195+
196+
steps:
197+
- name: Checkout
198+
uses: actions/checkout@v4
199+
200+
- name: Download Allure results
201+
uses: actions/download-artifact@v4
202+
with:
203+
path: ./allure-results
204+
205+
- name: Generate Allure report
206+
uses: simple-elf/allure-report-action@v1.7
207+
with:
208+
allure_results: ./allure-results
209+
allure_report: ./allure-report
210+
keep_reports: 20
211+
212+
- name: Setup Pages
213+
uses: actions/configure-pages@v4
214+
215+
- name: Upload GitHub Pages artifact
216+
uses: actions/upload-pages-artifact@v3
217+
with:
218+
path: ./allure-report
219+
220+
- name: Deploy to GitHub Pages
221+
id: deployment
222+
uses: actions/deploy-pages@v4
223+

Tests.csproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Allure.NUnit" Version="2.14.1" />
13+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
15+
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.58.0" />
16+
<PackageReference Include="NUnit" Version="4.3.2" />
17+
<PackageReference Include="NUnit.Analyzers" Version="4.7.0" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<Using Include="NUnit.Framework" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<None Include="e2e\testdata.json" CopyToOutputDirectory="PreserveNewest" />
27+
</ItemGroup>
28+
29+
</Project>
30+

e2e/BaseTest.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.Playwright.NUnit;
2+
using Allure.Net.Commons;
3+
using NUnit.Framework;
4+
using NUnit.Framework.Interfaces;
5+
6+
namespace E2ETests.e2e;
7+
8+
/// <summary>
9+
/// Base test class that provides access to Playwright's PageTest features,
10+
/// and common test utilities such as Allure attachments.
11+
/// </summary>
12+
public abstract class BaseTest : PageTest
13+
{
14+
[TearDown]
15+
public async Task CaptureScreenshotOnFailureAsync()
16+
{
17+
var outcome = TestContext.CurrentContext.Result.Outcome.Status;
18+
19+
if (outcome == TestStatus.Passed)
20+
{
21+
return;
22+
}
23+
24+
// Ensure we have a page (Playwright) and a place to store attachments.
25+
if (Page is null)
26+
{
27+
return;
28+
}
29+
30+
var testId = TestContext.CurrentContext.Test.ID;
31+
var testName = TestContext.CurrentContext.Test.Name;
32+
var workDir = TestContext.CurrentContext.WorkDirectory;
33+
34+
var screenshotsDir = Path.Combine(workDir, "allure-results");
35+
Directory.CreateDirectory(screenshotsDir);
36+
37+
var fileName = $"{SanitizeFileName(testName)}_{DateTime.UtcNow:yyyyMMdd_HHmmssfff}.png";
38+
var filePath = Path.Combine(screenshotsDir, fileName);
39+
40+
await Page.ScreenshotAsync(new()
41+
{
42+
Path = filePath,
43+
FullPage = true
44+
});
45+
46+
AllureApi.AddAttachment(
47+
$"Last page screenshot - {testName}",
48+
"image/png",
49+
filePath);
50+
}
51+
52+
private static string SanitizeFileName(string name)
53+
{
54+
foreach (var c in Path.GetInvalidFileNameChars())
55+
{
56+
name = name.Replace(c, '_');
57+
}
58+
59+
return name;
60+
}
61+
}
62+

e2e/Credentials.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace E2ETests.e2e;
2+
3+
// Legacy credentials class retained for backward compatibility.
4+
// New tests should use TestConfig.Current.Credentials instead.
5+
public static class Credentials { }
6+

e2e/LoginPageTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using E2ETests.e2e.pages;
2+
3+
namespace E2ETests.e2e;
4+
5+
public class LoginPageTests : BaseTest
6+
{
7+
[Test]
8+
[Category("smoke")]
9+
public async Task LoginPage_ShouldHaveExpectedHeading()
10+
{
11+
var loginPage = new LoginPage(Page);
12+
13+
await loginPage.GotoAsync();
14+
15+
var heading = await loginPage.GetHeadingAsync();
16+
17+
Assert.That(heading, Is.EqualTo(TestConfig.Current.LoginPage.Heading));
18+
}
19+
20+
[Test]
21+
public async Task LoginPage_ShouldHaveExpectedBodyText()
22+
{
23+
var loginPage = new LoginPage(Page);
24+
25+
await loginPage.GotoAsync();
26+
27+
var bodyText = await loginPage.GetBodyTextAsync();
28+
29+
Assert.That(bodyText.Trim(), Is.EqualTo(TestConfig.Current.LoginPage.BodyText));
30+
}
31+
32+
[Test]
33+
[Category("smoke")]
34+
public async Task InvalidLogin_ShouldShowFailureMessage()
35+
{
36+
var loginPage = new LoginPage(Page);
37+
38+
await loginPage.GotoAsync();
39+
await loginPage.LoginAsync("invalidUser", TestConfig.Current.Credentials.ValidPassword);
40+
41+
var flash = await loginPage.GetFlashMessageAsync();
42+
43+
Assert.That(flash, Does.StartWith(TestConfig.Current.LoginPage.InvalidUsernameMessagePrefix));
44+
}
45+
}
46+

0 commit comments

Comments
 (0)