-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New E2E Migration (PW) test project #31990
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a1507bd
New E2E Migration (PW) test project
HaoK c48a6ca
Update BinaryHttpClientTest.cs
HaoK c8e99db
Delete package.json
HaoK 5975e33
Update Microsoft.AspNetCore.Components.Migration.E2ETests.csproj
HaoK f72d949
Update Microsoft.AspNetCore.Components.Migration.E2ETests.csproj
HaoK 20a70ac
Update Microsoft.AspNetCore.Components.Migration.E2ETests.csproj
HaoK 0e7c9b8
Add playwright dependencies
HaoK 2fc7ea0
Update ServerFixture.cs
HaoK 183b7e8
Update Microsoft.AspNetCore.Components.Migration.E2ETests.csproj
HaoK 2f0f003
Update Microsoft.AspNetCore.Components.Migration.E2ETests.csproj
HaoK 2e425d6
Update Components.TestServer.csproj
HaoK 7d62f3f
Disable firefox and webkit (overrides not working?)
HaoK bb45c2a
Update helix-matrix.yml
HaoK 6bbb9b6
Skip helix arm queues for playwright
HaoK c054bb1
Skipped in helix target
HaoK 963373c
Update helix-matrix.yml
HaoK 9d8e901
Update Components.TestServer.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
<PropertyGroup Condition="'$(TestDependsOnPlaywright)' == 'true'"> | ||
<SkipHelixQueues>Windows.7.Amd64.Open;Windows.81.Amd64.Open;Redhat.7.Amd64.Open;Redhat.7.Amd64;Debian.9.Amd64.Open;Debian.9.Amd64.Open;Ubuntu.2004.Amd64.Open;Ubuntu.2004.Amd64;Ubuntu.1604.Amd64.Open;Ubuntu.1604.Amd64;Alpine.312.Amd64.Open;(Alpine.312.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.12-helix-20200908125345-56c6673;(Fedora.33.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:fedora-33-helix-20210120000908-a9df267</SkipHelixQueues> | ||
<SkipHelixArm>true</SkipHelixArm> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TestDependsOnPlaywright)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true'"> | ||
|
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
84 changes: 84 additions & 0 deletions
84
src/Components/test/E2ETestMigration/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,84 @@ | ||
// 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) { } | ||
|
||
protected async override Task InitializeCoreAsync(TestContext context) | ||
{ | ||
BrowserManager = await BrowserManager.CreateAsync(CreateConfiguration(), LoggerFactory); | ||
BrowserContextInfo = new ContextInformation(LoggerFactory); | ||
_output = new TestOutputLogger(Logger); | ||
} | ||
|
||
public Task InitializeAsync() => Task.CompletedTask; | ||
|
||
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(); | ||
|
||
private ITestOutputHelper _output; | ||
public ITestOutputHelper Output | ||
{ | ||
get | ||
{ | ||
if (_output == null) | ||
{ | ||
_output = new TestOutputLogger(Logger); | ||
} | ||
return _output; | ||
} | ||
} | ||
|
||
public ContextInformation BrowserContextInfo { get; protected set; } | ||
public BrowserManager BrowserManager { get; private set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Components/test/E2ETestMigration/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
...Components/test/E2ETestMigration/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
...ents/test/E2ETestMigration/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/E2ETestMigration/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()); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Components/test/E2ETestMigration/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,105 @@ | ||
// 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) | ||
{ | ||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))) | ||
{ | ||
var comma = projectName.IndexOf(",", StringComparison.Ordinal); | ||
if (comma != -1) | ||
{ | ||
projectName = projectName.Substring(0, comma); | ||
} | ||
if (string.Equals(projectName, "Components.TestServer", StringComparison.Ordinal)) | ||
{ | ||
projectName = "TestServer"; // This testasset doesn't match the folder name for some reason | ||
} | ||
var path = Path.Combine(AppContext.BaseDirectory, "testassets", projectName); | ||
if (!Directory.Exists(path)) | ||
{ | ||
throw new ArgumentException($"Cannot find a sample or test site directory: '{path}'."); | ||
} | ||
return path; | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.