Skip to content

Commit 768bad8

Browse files
committed
Add project files.
1 parent a595eee commit 768bad8

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed

Configs/testsettings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Environment": "qa",
3+
"BaseUrl": "https://demo.playwright.dev/todomvc",
4+
"Timeout": 10000,
5+
"RetryCount": 3,
6+
"Headless": true,
7+
"TakeScreenshotOnFailure": true
8+
}

Pages/TodosPage.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Playwright;
2+
3+
namespace PlaywrightTestFramework.Pages;
4+
5+
public class TodosPage(IPage page)
6+
{
7+
private readonly IPage _page = page;
8+
9+
private ILocator NewTodoInput => _page.Locator(".new-todo");
10+
private ILocator FirstTodoLabel => _page.Locator("ul.todo-list li:first-child label");
11+
private ILocator FirstTodoToggle => _page.Locator("ul.todo-list li:first-child .toggle");
12+
13+
public async Task NavigateAsync()
14+
=> await _page.GotoAsync("https://demo.playwright.dev/todomvc");
15+
16+
public async Task AddTodoAsync(string text)
17+
{
18+
await NewTodoInput.FillAsync(text);
19+
await NewTodoInput.PressAsync("Enter");
20+
}
21+
22+
public async Task<string> GetFirstTodoTextAsync()
23+
=> await FirstTodoLabel.InnerTextAsync();
24+
25+
public async Task ToggleFirstTodoAsync()
26+
=> await FirstTodoToggle.ClickAsync();
27+
}

PlaywrightTestFramework.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Folder Include="Screenshots\" />
11+
<Folder Include="Utils\" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
16+
<PackageReference Include="Microsoft.Playwright" Version="1.52.0" />
17+
<PackageReference Include="NUnit" Version="4.3.2" />
18+
<PackageReference Include="NUnit.Allure" Version="1.2.1.1" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
20+
<PackageReference Include="Polly" Version="8.6.0" />
21+
</ItemGroup>
22+
23+
</Project>

PlaywrightTestFramework.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36203.30 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightTestFramework", "PlaywrightTestFramework.csproj", "{1F866FCB-84D2-4EE3-A2F2-F07D2AD60A96}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1F866FCB-84D2-4EE3-A2F2-F07D2AD60A96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1F866FCB-84D2-4EE3-A2F2-F07D2AD60A96}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1F866FCB-84D2-4EE3-A2F2-F07D2AD60A96}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1F866FCB-84D2-4EE3-A2F2-F07D2AD60A96}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C757F7E3-ED63-49ED-BC39-EAD7CEB051DC}
24+
EndGlobalSection
25+
EndGlobal

Reports/AllureReports.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Allure.Commons;
2+
3+
namespace PlaywrightTestFramework.Reports;
4+
5+
public class AllureReports
6+
{
7+
public static string ResultDirectory => "Reports/Allure/results";
8+
9+
public static void Configure()
10+
{
11+
Environment.SetEnvironmentVariable("ALLURE_RESULTS_DIRECTORY", ResultDirectory);
12+
AllureLifecycle.Instance.CleanupResultDirectory();
13+
}
14+
}

Tests/TodosTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Allure.Commons;
2+
using Microsoft.Playwright;
3+
using NUnit.Allure.Attributes;
4+
using NUnit.Allure.Core;
5+
using NUnit.Framework;
6+
using PlaywrightTestFramework.Pages;
7+
using PlaywrightTestFramework.Reports;
8+
using System.IO;
9+
10+
11+
namespace PlaywrightTestFramework.Tests;
12+
13+
[AllureNUnit]
14+
public class TodosTests
15+
{
16+
private IPlaywright _playwright;
17+
private IBrowser _browser;
18+
private IPage _page;
19+
20+
[SetUp]
21+
public async Task SetUp()
22+
{
23+
AllureReports.Configure();
24+
_playwright = await Playwright.CreateAsync();
25+
_browser = await _playwright.Chromium.LaunchAsync(
26+
new BrowserTypeLaunchOptions { Headless = false });
27+
_page = await _browser.NewPageAsync();
28+
29+
}
30+
[Test, Category("PortfolioDemo")]
31+
[AllureTag("smoke")]
32+
[AllureSeverity(SeverityLevel.normal)]
33+
[AllureFeature("Demo Test")]
34+
public async Task AddAndToggleTodo_ShouldMarkItemCompleted()
35+
{
36+
var todo = new TodosPage(_page);
37+
await todo.NavigateAsync();
38+
39+
const string todoText = "Write awesome Playwright tests";
40+
await todo.AddTodoAsync(todoText);
41+
42+
Assert.That(await todo.GetFirstTodoTextAsync(), Is.EqualTo(todoText));
43+
44+
await todo.ToggleFirstTodoAsync();
45+
var classAttr = await _page.Locator("ul.todo-list li:first-child")
46+
.GetAttributeAsync("class");
47+
Assert.That(classAttr, Does.Contain("completed"));
48+
}
49+
50+
[TearDown]
51+
public async Task TearDown()
52+
{
53+
if (TestContext.CurrentContext.Result.Outcome.Status ==
54+
NUnit.Framework.Interfaces.TestStatus.Failed)
55+
{
56+
Directory.CreateDirectory("Screenshots");
57+
var file = Path.Combine("Screenshots",
58+
$"{TestContext.CurrentContext.Test.Name + DateTime.Today.ToString("dd MM yyyy hh mm ss ff")}.png");
59+
await _page.ScreenshotAsync(new PageScreenshotOptions { Path = file });
60+
Console.WriteLine($"Screenshot saved to: {Path.GetFullPath(file)}");
61+
AllureLifecycle.Instance.AddAttachment("Failure Screenshot", "image/png", file);
62+
63+
}
64+
65+
await _browser.CloseAsync();
66+
_playwright.Dispose();
67+
}
68+
}

0 commit comments

Comments
 (0)