-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[WIP] Add EToE tests which is the PW version of E2E #31137
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
Closed
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
0c1a690
Try splitting createbuildpublish from run
HaoK 44cfcbf
Merge branch 'main' into haok/pworder
HaoK 3f8f8df
Update BlazorWasmTemplateTest.cs
HaoK c4efe4b
Update BlazorWasmTemplateTest.cs
HaoK d5a4c14
Update BlazorServerTemplateTest.cs
HaoK 78a4740
Update BlazorWasmTemplateTest.cs
HaoK 24967f8
Try stop sharing playwright instance, create one per test
HaoK 1da6a3f
Update BrowserManager.cs
HaoK a201a63
Update AssemblyInfo.AssemblyFixtures.cs
HaoK 5c5d794
Update AssemblyInfo.AssemblyFixtures.cs
HaoK ccc0c10
Cleanup
HaoK d08ece3
Update BlazorTemplateTest.cs
HaoK 38a926e
Update BlazorWasmTemplateTest.cs
HaoK e205d24
Update BlazorWasmTemplateTest.cs
HaoK e856f9e
Add logging
HaoK 3d9921c
Merge branch 'haok/pworder' of https://github.com/dotnet/aspnetcore i…
HaoK 778d568
Update BlazorWasmTemplateTest.cs
HaoK 9b300b2
Update BlazorWasmTemplateTest.cs
HaoK c0aae25
Update BlazorTemplateTest.cs
HaoK 9cbac95
Update AssemblyInfo.AssemblyFixtures.cs
HaoK 488f245
Update BlazorWasmTemplateTest.cs
HaoK 811ad99
Merge branch 'main' into haok/pworder
HaoK 861afce
Update BlazorTemplateTest.cs
HaoK 1569cb2
Update BlazorTemplateTest.cs
HaoK 0e6f858
Update LoggedTestBase.cs
HaoK f2d395b
Update LoggedTestBase.cs
HaoK 54d171e
Update BlazorTemplateTest.cs
HaoK e204476
Update BlazorTemplateTest.cs
HaoK d31198f
Update BlazorServerTemplateTest.cs
HaoK 8b17ff6
Use correct logger
HaoK 9ab5a85
Update BlazorTemplateTest.cs
HaoK d4b6365
Update BlazorServerTemplateTest.cs
HaoK ad3f974
Update BlazorTemplateTest.cs
HaoK 9f47a47
Update BlazorWasmTemplateTest.cs
HaoK 3dede55
Update src/Testing/src/LoggedTest/LoggedTestBase.cs
HaoK 03c786f
Update LoggedTestBase.cs
HaoK d2c6bf8
Update BlazorTemplateTest.cs
HaoK e9d5124
Update MvcTemplateTest.cs
HaoK 70a67c9
Update BlazorTemplateTest.cs
HaoK d6723c0
Update BlazorTemplateTest.cs
HaoK 815ad0d
Hook testsink to actually do something!
HaoK 2678751
Update BlazorTemplateTest.cs
HaoK 968b57e
Pass output to project methods
HaoK e48461d
Fixup output helper in GetOrCreateProject
HaoK b7fadae
Merge branch 'main' into haok/pworder
HaoK c001819
Update Project.cs
HaoK 5172e66
Update ProjectFactoryFixture.cs
HaoK 69e6f31
Update Project.cs
HaoK f3f8317
Update MvcTemplateTest.cs
HaoK a050395
Update BlazorWasmTemplateTest.cs
HaoK 495da51
Update BlazorServerTemplateTest.cs
HaoK a57281f
Add EToE for components + pw
HaoK dc03942
Add build magic
HaoK 56e3216
Comment out test for now
HaoK 83146eb
Merge branch 'haok/pworder' into haok/etoe
HaoK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
src/Components/test/EToETest/Infrastructure/PlaywrightTestBase.cs
This file contains hidden or 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,89 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.BrowserTesting; | ||
using Microsoft.AspNetCore.Testing; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Testing; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure | ||
{ | ||
public class PlaywrightTestBase : LoggedTest, IAsyncLifetime | ||
{ | ||
private static readonly bool _isCIEnvironment = | ||
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ContinuousIntegrationBuild")); | ||
|
||
public PlaywrightTestBase(ITestOutputHelper output) : base(output) { } | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
var testSink = new TestSink(); | ||
testSink.MessageLogged += LogMessage; | ||
var factory = new TestLoggerFactory(testSink, enabled: true); | ||
BrowserManager = await BrowserManager.CreateAsync(CreateConfiguration(), factory); | ||
BrowserContextInfo = new ContextInformation(factory); | ||
|
||
void LogMessage(WriteContext ctx) | ||
{ | ||
TestOutputHelper.WriteLine($"{MapLogLevel(ctx)}: [Browser]{ctx.Message}"); | ||
|
||
static string MapLogLevel(WriteContext obj) => obj.LogLevel switch | ||
{ | ||
LogLevel.Trace => "trace", | ||
LogLevel.Debug => "dbug", | ||
LogLevel.Information => "info", | ||
LogLevel.Warning => "warn", | ||
LogLevel.Error => "error", | ||
LogLevel.Critical => "crit", | ||
LogLevel.None => "info", | ||
_ => "info" | ||
}; | ||
} | ||
} | ||
|
||
private static IConfiguration CreateConfiguration() | ||
{ | ||
var basePath = Path.GetDirectoryName(typeof(PlaywrightTestBase).Assembly.Location); | ||
var os = Environment.OSVersion.Platform switch | ||
{ | ||
PlatformID.Win32NT => "win", | ||
PlatformID.Unix => "linux", | ||
PlatformID.MacOSX => "osx", | ||
_ => null | ||
}; | ||
|
||
var builder = new ConfigurationBuilder() | ||
.AddJsonFile(Path.Combine(basePath, "playwrightSettings.json")) | ||
.AddJsonFile(Path.Combine(basePath, $"playwrightSettings.{os}.json"), optional: true); | ||
|
||
if (_isCIEnvironment) | ||
{ | ||
builder.AddJsonFile(Path.Combine(basePath, "playwrightSettings.ci.json"), optional: true) | ||
.AddJsonFile(Path.Combine(basePath, $"playwrightSettings.ci.{os}.json"), optional: true); | ||
} | ||
|
||
if (Debugger.IsAttached) | ||
{ | ||
builder.AddJsonFile(Path.Combine(basePath, "playwrightSettings.debug.json"), optional: true); | ||
} | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public Task DisposeAsync() => BrowserManager.DisposeAsync(); | ||
|
||
public ITestOutputHelper Output => TestOutputHelper; | ||
public ContextInformation BrowserContextInfo { get; protected set; } | ||
public BrowserManager BrowserManager { get; private set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Components/test/EToETest/Infrastructure/ServerFixtures/AspNetEnvironment.cs
This file contains hidden or 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,11 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
public enum AspNetEnvironment | ||
{ | ||
Development, | ||
Production | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Components/test/EToETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs
This file contains hidden or 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,47 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
public class AspNetSiteServerFixture : WebHostServerFixture | ||
{ | ||
public delegate IHost BuildWebHost(string[] args); | ||
|
||
public Assembly ApplicationAssembly { get; set; } | ||
|
||
public BuildWebHost BuildWebHostMethod { get; set; } | ||
|
||
public AspNetEnvironment Environment { get; set; } = AspNetEnvironment.Production; | ||
|
||
public List<string> AdditionalArguments { get; set; } = new List<string> { "--test-execution-mode", "server" }; | ||
|
||
protected override IHost CreateWebHost() | ||
{ | ||
if (BuildWebHostMethod == null) | ||
{ | ||
throw new InvalidOperationException( | ||
$"No value was provided for {nameof(BuildWebHostMethod)}"); | ||
} | ||
|
||
var assembly = ApplicationAssembly ?? BuildWebHostMethod.Method.DeclaringType.Assembly; | ||
var sampleSitePath = FindSampleOrTestSitePath(assembly.FullName); | ||
|
||
var host = "127.0.0.1"; | ||
|
||
return BuildWebHostMethod(new[] | ||
{ | ||
"--urls", $"http://{host}:0", | ||
"--contentroot", sampleSitePath, | ||
"--environment", Environment.ToString(), | ||
}.Concat(AdditionalArguments).ToArray()); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Components/test/EToETest/Infrastructure/ServerFixtures/BasicTestAppServerSiteFixture.cs
This file contains hidden or 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,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
public class BasicTestAppServerSiteFixture<TStartup> : AspNetSiteServerFixture where TStartup : class | ||
{ | ||
public BasicTestAppServerSiteFixture() | ||
{ | ||
BuildWebHostMethod = TestServer.Program.BuildWebHost<TStartup>; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Components/test/EToETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs
This file contains hidden or 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,40 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Extensions.Hosting; | ||
using System.Collections.Generic; | ||
using DevHostServerProgram = Microsoft.AspNetCore.Components.WebAssembly.DevServer.Server.Program; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
public class DevHostServerFixture<TProgram> : WebHostServerFixture | ||
{ | ||
public string Environment { get; set; } | ||
public string PathBase { get; set; } | ||
public string ContentRoot { get; private set; } | ||
|
||
protected override IHost CreateWebHost() | ||
{ | ||
ContentRoot = FindSampleOrTestSitePath( | ||
typeof(TProgram).Assembly.FullName); | ||
|
||
var host = "127.0.0.1"; | ||
|
||
var args = new List<string> | ||
{ | ||
"--urls", $"http://{host}:0", | ||
"--contentroot", ContentRoot, | ||
"--pathbase", PathBase, | ||
"--applicationpath", typeof(TProgram).Assembly.Location, | ||
}; | ||
|
||
if (!string.IsNullOrEmpty(Environment)) | ||
{ | ||
args.Add("--environment"); | ||
args.Add(Environment); | ||
} | ||
|
||
return DevHostServerProgram.BuildWebHost(args.ToArray()); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/Components/test/EToETest/Infrastructure/ServerFixtures/ServerFixture.cs
This file contains hidden or 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,86 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.ExceptionServices; | ||
using System.Threading; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
public abstract class ServerFixture : IDisposable | ||
{ | ||
private static readonly Lazy<Dictionary<string, string>> _projects = new Lazy<Dictionary<string, string>>(FindProjects); | ||
|
||
public Uri RootUri => _rootUriInitializer.Value; | ||
|
||
private readonly Lazy<Uri> _rootUriInitializer; | ||
|
||
public ServerFixture() | ||
{ | ||
_rootUriInitializer = new Lazy<Uri>(() => | ||
{ | ||
var uri = new Uri(StartAndGetRootUri()); | ||
|
||
return uri; | ||
}); | ||
} | ||
|
||
public abstract void Dispose(); | ||
|
||
protected abstract string StartAndGetRootUri(); | ||
|
||
private static Dictionary<string, string> FindProjects() | ||
{ | ||
return typeof(ServerFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>() | ||
.Where(m => m.Key.StartsWith("TestAssemblyApplication[", StringComparison.Ordinal)) | ||
.ToDictionary(m => | ||
m.Key.Replace("TestAssemblyApplication", "").TrimStart('[').TrimEnd(']'), | ||
m => m.Value); | ||
} | ||
|
||
public static string FindSampleOrTestSitePath(string projectName) | ||
{ | ||
var projects = _projects.Value; | ||
if (projects.TryGetValue(projectName, out var dir)) | ||
{ | ||
return dir; | ||
} | ||
|
||
throw new ArgumentException($"Cannot find a sample or test site with name '{projectName}'."); | ||
} | ||
|
||
protected static void RunInBackgroundThread(Action action) | ||
{ | ||
var isDone = new ManualResetEvent(false); | ||
|
||
ExceptionDispatchInfo edi = null; | ||
new Thread(() => | ||
{ | ||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
edi = ExceptionDispatchInfo.Capture(ex); | ||
} | ||
|
||
isDone.Set(); | ||
}).Start(); | ||
|
||
if (!isDone.WaitOne(TimeSpan.FromSeconds(10))) | ||
{ | ||
throw new TimeoutException("Timed out waiting for: " + action); | ||
} | ||
|
||
if (edi != null) | ||
{ | ||
throw edi.SourceException; | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Components/test/EToETest/Infrastructure/ServerFixtures/StaticSiteServerFixture.cs
This file contains hidden or 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,49 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures | ||
{ | ||
// Although this is not used for anything meaningful related to Blazor yet, it | ||
// will be used later when there's a mechanism for publishing standalone Blazor | ||
// apps as a set of purely static files and we need E2E testing on the result. | ||
|
||
public class StaticSiteServerFixture : WebHostServerFixture | ||
{ | ||
public string SampleSiteName { get; set; } | ||
|
||
protected override IHost CreateWebHost() | ||
{ | ||
if (string.IsNullOrEmpty(SampleSiteName)) | ||
{ | ||
throw new InvalidOperationException($"No value was provided for {nameof(SampleSiteName)}"); | ||
} | ||
|
||
var sampleSitePath = FindSampleOrTestSitePath(SampleSiteName); | ||
|
||
var host = "127.0.0.1"; | ||
|
||
return new HostBuilder() | ||
.ConfigureWebHost(webHostBuilder => webHostBuilder | ||
.UseKestrel() | ||
.UseContentRoot(sampleSitePath) | ||
.UseWebRoot(string.Empty) | ||
.UseStartup<StaticSiteStartup>() | ||
.UseUrls($"http://{host}:0")) | ||
.Build(); | ||
} | ||
|
||
private class StaticSiteStartup | ||
{ | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseFileServer(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
PlayweightE2ETests
so it's clear how they are different?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gamer in me can't help but think P2W with this particular combination of letters P2W.Tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not put other product names in test projects. Those things change and become stale. We can call them Components.FunctionalTests or Component.EndToEnd or a similar generic name. In the end, if/when the migration is successful we can delete the old project and name the new project Components.E2ETests again if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make a specific goal of eventually removing the old
Components.E2ETests
and having the new one take that name? That would make sense to me.In the meantime, it would be great for the new project to have some name that indicates why it exists. It will be really hard for anyone coming fresh to the repo to understand why we have both
E2ETests
andEToETests
. How about calling the new oneE2ETestMigration
or similar, with the goal that we eventually replace the old one and rename it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will start a new PR since this has gotten stale, with rebased from main, with E2ETestMigration as the folder, and the csproj will be the same just with an additional
Components.Migration.E2ETests.csproj