Skip to content

Commit 8cb5ed9

Browse files
Playwright E2E tests (Megabit#4709)
* Delete Selenium E2E Tests. Add Playwright E2E Tests. * Carry over more playwright / bunit changes * update ci * add .runsettings * update build.cmd * remove blank folders for now * removed failing test on mladen's machine from execution * ValidateTextEditComponentTest as async * Autocomplete bunit tests as async * Clean readme * Remove unused settings * Refactor BasicTestApp.Server.Program. Don't Use TopLevelStatements. --------- Co-authored-by: Mladen Macanovic <[email protected]>
1 parent 1081046 commit 8cb5ed9

File tree

76 files changed

+1610
-3188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1610
-3188
lines changed

.github/workflows/blazorise-ci-basic.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212

1313
- name: Setup .NET 6
14-
uses: actions/setup-dotnet@v1
14+
uses: actions/setup-dotnet@v3
1515
with:
1616
dotnet-version: '6.0.x'
1717
include-prerelease: true
1818

1919
- name: Setup .NET 7
20-
uses: actions/setup-dotnet@v1
20+
uses: actions/setup-dotnet@v3
2121
with:
2222
dotnet-version: '7.0.x'
2323
include-prerelease: true
@@ -30,3 +30,9 @@ jobs:
3030

3131
- name: Run Unit Tests - Release
3232
run: dotnet test ./Tests/Blazorise.Tests/Blazorise.Tests.csproj --configuration Release --no-restore --no-build --verbosity normal
33+
34+
- name: Prepare E2E Tests Dependencies
35+
run: pwsh ./Tests/Blazorise.E2E.Tests/bin/Release/net7.0/playwright.ps1 install --with-deps
36+
37+
- name: Run E2E Tests - Release
38+
run: dotnet test ./Tests/Blazorise.E2E.Tests/Blazorise.E2E.Tests.csproj --configuration Release --no-restore --no-build --verbosity normal

.runsettings

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<RunSettings>
3+
4+
<NUnit>
5+
<NumberOfTestWorkers>4</NumberOfTestWorkers>
6+
</NUnit>
7+
8+
<RunConfiguration>
9+
<EnvironmentVariables>
10+
<!-- For debugging selectors, it's recommend to set the following environment variable -->
11+
<!--<DEBUG>pw:api</DEBUG>-->
12+
</EnvironmentVariables>
13+
</RunConfiguration>
14+
15+
<Playwright>
16+
<BrowserName>chromium</BrowserName>
17+
<LaunchOptions>
18+
<Headless>true</Headless>
19+
<Args>--disable-gpu --no-sandbox</Args>
20+
<Channel>msedge</Channel>
21+
</LaunchOptions>
22+
</Playwright>
23+
</RunSettings>

Blazorise.sln

+8-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ EndProject
3838
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D1FF70C6-E002-47C3-B2D0-D0FFEF2BF37A}"
3939
ProjectSection(SolutionItems) = preProject
4040
.editorconfig = .editorconfig
41+
.runsettings = .runsettings
4142
EndProjectSection
4243
EndProject
4344
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Charts.Streaming", "Source\Extensions\Blazorise.Charts.Streaming\Blazorise.Charts.Streaming.csproj", "{9AA305DA-A667-49E6-BDDA-7C976AD5BB3B}"
@@ -62,8 +63,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApp", "Demos\Apps\TodoA
6263
EndProject
6364
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{47240431-396C-4187-941A-9511D7B79D8D}"
6465
EndProject
65-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.E2ETests", "Tests\Blazorise.E2ETests\Blazorise.E2ETests.csproj", "{A4218BB6-81C3-47A6-80F2-6FF6E227D142}"
66-
EndProject
6766
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Tests", "Tests\Blazorise.Tests\Blazorise.Tests.csproj", "{8D91050E-1ACF-40C5-9DA4-5F94AB149A5E}"
6867
EndProject
6968
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.RichTextEdit", "Source\Extensions\Blazorise.RichTextEdit\Blazorise.RichTextEdit.csproj", "{EB4A0C35-C45D-4F0F-BF03-3ACFB53CB865}"
@@ -129,6 +128,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Tailwind", "Sourc
129128
EndProject
130129
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Demo.Tailwind", "Demos\Blazorise.Demo.Tailwind\Blazorise.Demo.Tailwind.csproj", "{47EEB5B2-3CA1-436C-8317-E69F611FA1E3}"
131130
EndProject
131+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.E2E.Tests", "Tests\Blazorise.E2E.Tests\Blazorise.E2E.Tests.csproj", "{FA75DC9B-32F0-41DC-A51D-F851E79D62DB}"
132+
EndProject
132133
Global
133134
GlobalSection(SolutionConfigurationPlatforms) = preSolution
134135
Debug|Any CPU = Debug|Any CPU
@@ -223,10 +224,6 @@ Global
223224
{FD072A38-6D23-49C1-93F9-4D7584A8A4A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
224225
{FD072A38-6D23-49C1-93F9-4D7584A8A4A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
225226
{FD072A38-6D23-49C1-93F9-4D7584A8A4A7}.Release|Any CPU.Build.0 = Release|Any CPU
226-
{A4218BB6-81C3-47A6-80F2-6FF6E227D142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
227-
{A4218BB6-81C3-47A6-80F2-6FF6E227D142}.Debug|Any CPU.Build.0 = Debug|Any CPU
228-
{A4218BB6-81C3-47A6-80F2-6FF6E227D142}.Release|Any CPU.ActiveCfg = Release|Any CPU
229-
{A4218BB6-81C3-47A6-80F2-6FF6E227D142}.Release|Any CPU.Build.0 = Release|Any CPU
230227
{8D91050E-1ACF-40C5-9DA4-5F94AB149A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
231228
{8D91050E-1ACF-40C5-9DA4-5F94AB149A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
232229
{8D91050E-1ACF-40C5-9DA4-5F94AB149A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -339,6 +336,10 @@ Global
339336
{47EEB5B2-3CA1-436C-8317-E69F611FA1E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
340337
{47EEB5B2-3CA1-436C-8317-E69F611FA1E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
341338
{47EEB5B2-3CA1-436C-8317-E69F611FA1E3}.Release|Any CPU.Build.0 = Release|Any CPU
339+
{FA75DC9B-32F0-41DC-A51D-F851E79D62DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
340+
{FA75DC9B-32F0-41DC-A51D-F851E79D62DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
341+
{FA75DC9B-32F0-41DC-A51D-F851E79D62DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
342+
{FA75DC9B-32F0-41DC-A51D-F851E79D62DB}.Release|Any CPU.Build.0 = Release|Any CPU
342343
EndGlobalSection
343344
GlobalSection(SolutionProperties) = preSolution
344345
HideSolutionNode = FALSE
@@ -368,7 +369,6 @@ Global
368369
{4DEB65E7-40BA-409E-9C26-6EF75ADF2601} = {C2D0A89F-530E-413F-9D0E-9EE2129A2275}
369370
{FD072A38-6D23-49C1-93F9-4D7584A8A4A7} = {47240431-396C-4187-941A-9511D7B79D8D}
370371
{47240431-396C-4187-941A-9511D7B79D8D} = {C2D0A89F-530E-413F-9D0E-9EE2129A2275}
371-
{A4218BB6-81C3-47A6-80F2-6FF6E227D142} = {D04C5874-4D6A-493E-8CF4-6C7922198563}
372372
{8D91050E-1ACF-40C5-9DA4-5F94AB149A5E} = {D04C5874-4D6A-493E-8CF4-6C7922198563}
373373
{EB4A0C35-C45D-4F0F-BF03-3ACFB53CB865} = {9731051E-0AA7-411E-A76A-987854F034DA}
374374
{83B3D727-2C23-4A95-8478-85A854BA8325} = {9731051E-0AA7-411E-A76A-987854F034DA}
@@ -397,6 +397,7 @@ Global
397397
{F9515890-3956-47A7-A8BB-B27333F4FC57} = {C2D0A89F-530E-413F-9D0E-9EE2129A2275}
398398
{452E1C4E-F81A-46EC-AA86-7CC53FB1BCB3} = {73CD9574-5204-442D-A67C-CA7B038057C2}
399399
{47EEB5B2-3CA1-436C-8317-E69F611FA1E3} = {C2D0A89F-530E-413F-9D0E-9EE2129A2275}
400+
{FA75DC9B-32F0-41DC-A51D-F851E79D62DB} = {D04C5874-4D6A-493E-8CF4-6C7922198563}
400401
EndGlobalSection
401402
GlobalSection(ExtensibilityGlobals) = postSolution
402403
SolutionGuid = {205B3EA4-470F-45DA-911E-346AF7D0A9A5}

Tests/BasicTestApp.Client/BasicTestApp.Client.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net7.0</TargetFramework>
5-
<OutputType>Exe</OutputType>
6-
<LangVersion>10.0</LangVersion>
5+
<GenerateBlazorWebAssemblyDepsFile>true</GenerateBlazorWebAssemblyDepsFile>
76
</PropertyGroup>
87

98
<ItemGroup>

Tests/BasicTestApp.Server/Program.cs

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
using Microsoft.AspNetCore;
2-
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.Extensions.Configuration;
1+

2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.Logging;
44

55
namespace BasicTestApp.Server;
6-
7-
public class Program
6+
public partial class Program
87
{
98
public static void Main( string[] args )
109
{
11-
BuildWebHost( args ).Run();
10+
var builder = WebApplication.CreateBuilder( args );
11+
builder.Logging.ClearProviders();
12+
13+
WebApplication app = builder.Build();
14+
15+
//app.UseWebAssemblyDebugging();
16+
//app.UseHttpsRedirection();
17+
18+
app.UseBlazorFrameworkFiles();
19+
app.UseStaticFiles();
20+
21+
app.UseRouting();
22+
23+
app.MapFallbackToFile( "index.html" );
24+
25+
app.Run();
1226
}
27+
}
28+
29+
public partial class Program { }
1330

14-
public static IWebHost BuildWebHost( string[] args ) =>
15-
WebHost.CreateDefaultBuilder( args )
16-
.UseConfiguration( new ConfigurationBuilder()
17-
.AddCommandLine( args )
18-
.Build() )
19-
.UseStartup<Startup>()
20-
.UseStaticWebAssets()
21-
.Build();
22-
}

Tests/BasicTestApp.Server/Startup.cs

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
7+
<IsPackable>false</IsPackable>
8+
<IsTestProject>true</IsTestProject>
9+
<PreserveCompilationContext>true</PreserveCompilationContext>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.4" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
15+
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.31.1" />
16+
<PackageReference Include="coverlet.collector" Version="3.1.2">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\BasicTestApp.Server\BasicTestApp.Server.csproj" />
25+
</ItemGroup>
26+
27+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace Blazorise.E2E.Tests;
2+
3+
4+
[Parallelizable( ParallelScope.Self )]
5+
[TestFixture]
6+
public class DefaultExampleTests : PageTest
7+
{
8+
/// <summary>
9+
/// This test serves as simple example of how to use Playwright. This was taken off playwright .NET docs.
10+
/// </summary>
11+
/// <returns></returns>
12+
//[Test]
13+
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
14+
{
15+
// Pause on the following line.
16+
await Page.PauseAsync();
17+
18+
await Page.GotoAsync( "https://playwright.dev" );
19+
20+
// Expect a title "to contain" a substring.
21+
await Expect( Page ).ToHaveTitleAsync( new Regex( "Playwright" ) );
22+
23+
// create a locator
24+
var getStarted = Page.GetByRole( AriaRole.Link, new() { Name = "Get started" } );
25+
26+
// Expect an attribute "to be strictly equal" to the value.
27+
await Expect( getStarted ).ToHaveAttributeAsync( "href", "/docs/intro" );
28+
29+
// Click the get started link.
30+
await getStarted.ClickAsync();
31+
32+
// Expects the URL to contain intro.
33+
await Expect( Page ).ToHaveURLAsync( new Regex( ".*intro" ) );
34+
}
35+
}
36+
37+
[Parallelizable( ParallelScope.Self )]
38+
[TestFixture]
39+
public class CopyMeTests : BlazorisePageTest
40+
{
41+
[Test]
42+
public async Task CopyMe()
43+
{
44+
await SelectTestComponent<ButtonComponent>();
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Microsoft.AspNetCore.Mvc.Testing;
2+
3+
namespace Blazorise.E2E.Tests.Infrastructure;
4+
5+
/// <summary>
6+
/// Credit to : https://www.youtube.com/watch?v=lJa3YlUliEs
7+
/// </summary>
8+
public class BlazorPageTest : PageTest
9+
{
10+
11+
protected static readonly Uri RootUri = new( "http://localhost:14695" );
12+
13+
private readonly WebApplicationFactory<BasicTestApp.Server.Program> _webApplicationFactory = new() { };
14+
private HttpClient _httpClient;
15+
16+
[SetUp]
17+
public async Task Setup()
18+
{
19+
_httpClient = _webApplicationFactory.CreateClient( new()
20+
{
21+
BaseAddress = RootUri,
22+
} );
23+
24+
await Context.RouteAsync( $"{RootUri.AbsoluteUri}**", async route =>
25+
{
26+
var request = route.Request;
27+
var content = request.PostDataBuffer is { } postDataBuffer
28+
? new ByteArrayContent( postDataBuffer )
29+
: null;
30+
31+
var requestMessage = new HttpRequestMessage( new( request.Method ), request.Url )
32+
{
33+
Content = content
34+
};
35+
36+
foreach ( var header in request.Headers )
37+
{
38+
requestMessage.Headers.Add( header.Key, header.Value );
39+
}
40+
41+
var response = await _httpClient.SendAsync( requestMessage );
42+
var responseBody = await response.Content.ReadAsByteArrayAsync();
43+
var responseHeaders = response.Content.Headers.Select( x => KeyValuePair.Create( x.Key, x.Value.FirstOrDefault() ?? string.Empty ) );
44+
45+
await route.FulfillAsync( new()
46+
{
47+
BodyBytes = responseBody,
48+
Headers = responseHeaders,
49+
Status = (int)response.StatusCode
50+
} );
51+
52+
} );
53+
}
54+
55+
[TearDown]
56+
public void TearDown()
57+
{
58+
_httpClient?.Dispose();
59+
}
60+
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace Blazorise.E2E.Tests.Infrastructure;
4+
5+
6+
public class BlazorisePageTest : BlazorPageTest
7+
{
8+
/// <summary>
9+
/// Override browser context options if needed.
10+
/// </summary>
11+
/// <returns></returns>
12+
public override BrowserNewContextOptions ContextOptions()
13+
{
14+
return new BrowserNewContextOptions()
15+
{
16+
Locale = "en-US"
17+
};
18+
}
19+
20+
/// <summary>
21+
/// This is an helper specific to our test project, where we have a dropdown selection with the full name of the components.
22+
/// This will also navigate to the root page.
23+
/// </summary>
24+
/// <typeparam name="TComponent"></typeparam>
25+
/// <returns></returns>
26+
protected async Task SelectTestComponent<TComponent>() where TComponent : IComponent
27+
{
28+
await Page.GotoAsync( RootUri.AbsoluteUri );
29+
30+
var componentTypeName = typeof( TComponent ).FullName;
31+
await Page.GetByRole( AriaRole.Combobox ).SelectOptionAsync( new[] { componentTypeName } );
32+
}
33+
34+
35+
}

0 commit comments

Comments
 (0)