-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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]>
- Loading branch information
1 parent
1081046
commit 8cb5ed9
Showing
76 changed files
with
1,610 additions
and
3,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<RunSettings> | ||
|
||
<NUnit> | ||
<NumberOfTestWorkers>4</NumberOfTestWorkers> | ||
</NUnit> | ||
|
||
<RunConfiguration> | ||
<EnvironmentVariables> | ||
<!-- For debugging selectors, it's recommend to set the following environment variable --> | ||
<!--<DEBUG>pw:api</DEBUG>--> | ||
</EnvironmentVariables> | ||
</RunConfiguration> | ||
|
||
<Playwright> | ||
<BrowserName>chromium</BrowserName> | ||
<LaunchOptions> | ||
<Headless>true</Headless> | ||
<Args>--disable-gpu --no-sandbox</Args> | ||
<Channel>msedge</Channel> | ||
</LaunchOptions> | ||
</Playwright> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
| ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BasicTestApp.Server; | ||
|
||
public class Program | ||
public partial class Program | ||
{ | ||
public static void Main( string[] args ) | ||
{ | ||
BuildWebHost( args ).Run(); | ||
var builder = WebApplication.CreateBuilder( args ); | ||
builder.Logging.ClearProviders(); | ||
|
||
WebApplication app = builder.Build(); | ||
|
||
//app.UseWebAssemblyDebugging(); | ||
//app.UseHttpsRedirection(); | ||
|
||
app.UseBlazorFrameworkFiles(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.MapFallbackToFile( "index.html" ); | ||
|
||
app.Run(); | ||
} | ||
} | ||
|
||
public partial class Program { } | ||
|
||
public static IWebHost BuildWebHost( string[] args ) => | ||
WebHost.CreateDefaultBuilder( args ) | ||
.UseConfiguration( new ConfigurationBuilder() | ||
.AddCommandLine( args ) | ||
.Build() ) | ||
.UseStartup<Startup>() | ||
.UseStaticWebAssets() | ||
.Build(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.4" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.31.1" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BasicTestApp.Server\BasicTestApp.Server.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace Blazorise.E2E.Tests; | ||
|
||
|
||
[Parallelizable( ParallelScope.Self )] | ||
[TestFixture] | ||
public class DefaultExampleTests : PageTest | ||
{ | ||
/// <summary> | ||
/// This test serves as simple example of how to use Playwright. This was taken off playwright .NET docs. | ||
/// </summary> | ||
/// <returns></returns> | ||
//[Test] | ||
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage() | ||
{ | ||
// Pause on the following line. | ||
await Page.PauseAsync(); | ||
|
||
await Page.GotoAsync( "https://playwright.dev" ); | ||
|
||
// Expect a title "to contain" a substring. | ||
await Expect( Page ).ToHaveTitleAsync( new Regex( "Playwright" ) ); | ||
|
||
// create a locator | ||
var getStarted = Page.GetByRole( AriaRole.Link, new() { Name = "Get started" } ); | ||
|
||
// Expect an attribute "to be strictly equal" to the value. | ||
await Expect( getStarted ).ToHaveAttributeAsync( "href", "/docs/intro" ); | ||
|
||
// Click the get started link. | ||
await getStarted.ClickAsync(); | ||
|
||
// Expects the URL to contain intro. | ||
await Expect( Page ).ToHaveURLAsync( new Regex( ".*intro" ) ); | ||
} | ||
} | ||
|
||
[Parallelizable( ParallelScope.Self )] | ||
[TestFixture] | ||
public class CopyMeTests : BlazorisePageTest | ||
{ | ||
[Test] | ||
public async Task CopyMe() | ||
{ | ||
await SelectTestComponent<ButtonComponent>(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Tests/Blazorise.E2E.Tests/Infrastructure/BlazorPageTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace Blazorise.E2E.Tests.Infrastructure; | ||
|
||
/// <summary> | ||
/// Credit to : https://www.youtube.com/watch?v=lJa3YlUliEs | ||
/// </summary> | ||
public class BlazorPageTest : PageTest | ||
{ | ||
|
||
protected static readonly Uri RootUri = new( "http://localhost:14695" ); | ||
|
||
private readonly WebApplicationFactory<BasicTestApp.Server.Program> _webApplicationFactory = new() { }; | ||
private HttpClient _httpClient; | ||
|
||
[SetUp] | ||
public async Task Setup() | ||
{ | ||
_httpClient = _webApplicationFactory.CreateClient( new() | ||
{ | ||
BaseAddress = RootUri, | ||
} ); | ||
|
||
await Context.RouteAsync( $"{RootUri.AbsoluteUri}**", async route => | ||
{ | ||
var request = route.Request; | ||
var content = request.PostDataBuffer is { } postDataBuffer | ||
? new ByteArrayContent( postDataBuffer ) | ||
: null; | ||
|
||
var requestMessage = new HttpRequestMessage( new( request.Method ), request.Url ) | ||
{ | ||
Content = content | ||
}; | ||
|
||
foreach ( var header in request.Headers ) | ||
{ | ||
requestMessage.Headers.Add( header.Key, header.Value ); | ||
} | ||
|
||
var response = await _httpClient.SendAsync( requestMessage ); | ||
var responseBody = await response.Content.ReadAsByteArrayAsync(); | ||
var responseHeaders = response.Content.Headers.Select( x => KeyValuePair.Create( x.Key, x.Value.FirstOrDefault() ?? string.Empty ) ); | ||
|
||
await route.FulfillAsync( new() | ||
{ | ||
BodyBytes = responseBody, | ||
Headers = responseHeaders, | ||
Status = (int)response.StatusCode | ||
} ); | ||
|
||
} ); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_httpClient?.Dispose(); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
Tests/Blazorise.E2E.Tests/Infrastructure/BlazorisePageTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Blazorise.E2E.Tests.Infrastructure; | ||
|
||
|
||
public class BlazorisePageTest : BlazorPageTest | ||
{ | ||
/// <summary> | ||
/// Override browser context options if needed. | ||
/// </summary> | ||
/// <returns></returns> | ||
public override BrowserNewContextOptions ContextOptions() | ||
{ | ||
return new BrowserNewContextOptions() | ||
{ | ||
Locale = "en-US" | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// This is an helper specific to our test project, where we have a dropdown selection with the full name of the components. | ||
/// This will also navigate to the root page. | ||
/// </summary> | ||
/// <typeparam name="TComponent"></typeparam> | ||
/// <returns></returns> | ||
protected async Task SelectTestComponent<TComponent>() where TComponent : IComponent | ||
{ | ||
await Page.GotoAsync( RootUri.AbsoluteUri ); | ||
|
||
var componentTypeName = typeof( TComponent ).FullName; | ||
await Page.GetByRole( AriaRole.Combobox ).SelectOptionAsync( new[] { componentTypeName } ); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.