Skip to content

Commit c7770a5

Browse files
committed
[Templating][Components] Unify and improve E2E testing infrastructure
* Unify the Templating and Components testing infrastructure. * Enable test project discovery in the components E2E tests.
1 parent 17344cd commit c7770a5

File tree

63 files changed

+1759
-1166
lines changed

Some content is hidden

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

63 files changed

+1759
-1166
lines changed

.azure/pipelines/jobs/default-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ jobs:
123123
- ${{ if and(eq(parameters.installJdk, 'true'), eq(parameters.agentOs, 'Windows')) }}:
124124
- powershell: ./eng/scripts/InstallJdk.ps1 '11.0.1'
125125
displayName: Install JDK 11
126+
- powershell: Write-Host "##vso[task.prependpath]$env:JAVA_HOME\bin"
127+
displayName: Prepend JAVA bin folder to the PATH.
128+
- powershell: ./eng/scripts/InstallGoogleChrome.ps1
129+
displayName: Install chrome
126130
- ${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.agentOs, 'Windows'), eq(parameters.codeSign, 'true')) }}:
127131
- task: MicroBuildSigningPlugin@1
128132
displayName: Install MicroBuild Signing plugin

eng/scripts/InstallGoogleChrome.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$InstallerPath = "$env:Temp\chrome_installer.exe";
2+
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $InstallerPath;
3+
Start-Process -FilePath $InstallerPath -Args "/silent /install" -Verb RunAs -Wait;
4+
Remove-Item $InstallerPath

src/Components/test/E2ETest/Infrastructure/BasicTestAppTestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using OpenQA.Selenium.Support.UI;
910
using System;

src/Components/test/E2ETest/Infrastructure/BrowserFixture.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Components/test/E2ETest/Infrastructure/CaptureSeleniumLogsAttribute.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Components/test/E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -24,7 +24,7 @@ protected override IWebHost CreateWebHost()
2424
}
2525

2626
var sampleSitePath = FindSampleOrTestSitePath(
27-
BuildWebHostMethod.Method.DeclaringType.Assembly.GetName().Name);
27+
BuildWebHostMethod.Method.DeclaringType.Assembly.FullName);
2828

2929
return BuildWebHostMethod(new[]
3030
{

src/Components/test/E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Hosting;
@@ -16,7 +16,7 @@ public class DevHostServerFixture<TProgram> : WebHostServerFixture
1616
protected override IWebHost CreateWebHost()
1717
{
1818
ContentRoot = FindSampleOrTestSitePath(
19-
typeof(TProgram).Assembly.GetName().Name);
19+
typeof(TProgram).Assembly.FullName);
2020

2121
var args = new List<string>
2222
{

src/Components/test/E2ETest/Infrastructure/ServerFixtures/ServerFixture.cs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8+
using System.Reflection;
89
using System.Threading;
910

1011
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
@@ -27,26 +28,13 @@ public ServerFixture()
2728

2829
protected abstract string StartAndGetRootUri();
2930

30-
protected static string FindSolutionDir()
31-
{
32-
return FindClosestDirectoryContaining(
33-
"Components.sln",
34-
Path.GetDirectoryName(typeof(ServerFixture).Assembly.Location));
35-
}
36-
3731
private static Dictionary<string, string> FindProjects()
3832
{
39-
var solutionDir = FindSolutionDir();
40-
41-
var testAssetsDirectories = new[]
42-
{
43-
Path.Combine(solutionDir, "test", "testassets"),
44-
Path.Combine(solutionDir, "blazor", "testassets"),
45-
};
46-
47-
return testAssetsDirectories
48-
.SelectMany(d => new DirectoryInfo(d).EnumerateDirectories())
49-
.ToDictionary(d => d.Name, d => d.FullName);
33+
return typeof(ServerFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
34+
.Where(m => m.Key.StartsWith("TestAssemblyApplication["))
35+
.ToDictionary(m =>
36+
m.Key.Replace("TestAssemblyApplication", "").TrimStart('[').TrimEnd(']'),
37+
m => m.Value);
5038
}
5139

5240
protected static string FindSampleOrTestSitePath(string projectName)
@@ -60,28 +48,6 @@ protected static string FindSampleOrTestSitePath(string projectName)
6048
throw new ArgumentException($"Cannot find a sample or test site with name '{projectName}'.");
6149
}
6250

63-
private static string FindClosestDirectoryContaining(
64-
string filename,
65-
string startDirectory)
66-
{
67-
var dir = startDirectory;
68-
while (true)
69-
{
70-
if (File.Exists(Path.Combine(dir, filename)))
71-
{
72-
return dir;
73-
}
74-
75-
dir = Directory.GetParent(dir)?.FullName;
76-
if (string.IsNullOrEmpty(dir))
77-
{
78-
throw new FileNotFoundException(
79-
$"Could not locate a file called '{filename}' in " +
80-
$"directory '{startDirectory}' or any parent directory.");
81-
}
82-
}
83-
}
84-
8551
protected static void RunInBackgroundThread(Action action)
8652
{
8753
var isDone = new ManualResetEvent(false);

src/Components/test/E2ETest/Infrastructure/ServerTestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
5+
using Microsoft.AspNetCore.E2ETesting;
56
using System;
67
using Xunit;
78
using Xunit.Abstractions;
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<!-- Shared testing infrastructure for running E2E tests using selenium -->
4+
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.props" />
5+
36
<PropertyGroup>
47
<TargetFramework>netcoreapp3.0</TargetFramework>
5-
<DefaultItemExcludes>$(DefaultItemExcludes);node_modules\**</DefaultItemExcludes>
6-
<!-- WebDriver is not strong-named signed -->
7-
<SignAssembly>false</SignAssembly>
8+
<TestGroupName>Components.E2ETests</TestGroupName>
89

910
<!--
1011
Temporarily disabled until this runs on macOS
1112
-->
12-
<SkipTests Condition="'$(BlazorAllTests)' != 'true'">true</SkipTests>
13+
<SkipTests Condition="'$(SeleniumE2ETestsSupported)' != 'true'">true</SkipTests>
1314
<!-- https://github.com/aspnet/AspNetCore/issues/6857 -->
1415
<BuildHelixPayload>false</BuildHelixPayload>
1516
</PropertyGroup>
@@ -18,20 +19,10 @@
1819
<Compile Include="$(SharedSourceRoot)Process\**\*.cs" LinkBase="Shared" />
1920
</ItemGroup>
2021

21-
<!-- Version of this SDK is set in global.json -->
22-
<Sdk Name="Yarn.MSBuild" />
23-
24-
<Target Name="EnsureNodeJSRestored" BeforeTargets="Build" Condition="'$(BlazorAllTests)'=='true'">
25-
<Message Text="Running yarn install on $(MSBuildProjectFile)" Importance="High" />
26-
<Yarn Command="install" />
27-
</Target>
28-
2922
<ItemGroup>
3023
<Reference Include="Microsoft.AspNetCore.Hosting" />
3124
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
3225
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
33-
<Reference Include="Selenium.Support" />
34-
<Reference Include="Selenium.WebDriver" />
3526
</ItemGroup>
3627

3728
<ItemGroup>
@@ -48,4 +39,7 @@
4839
<ProjectReference Include="..\testassets\TestServer\TestServer.csproj" />
4940
</ItemGroup>
5041

42+
<!-- Shared testing infrastructure for running E2E tests using selenium -->
43+
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.targets" />
44+
5145
</Project>

src/Components/test/E2ETest/ServerExecutionTests/ServerComponentRenderingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using System;
55
using BasicTestApp;
66
using ComponentsApp.App.Pages;
7-
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
87
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
98
using Microsoft.AspNetCore.Components.E2ETest.Tests;
9+
using Microsoft.AspNetCore.E2ETesting;
1010
using OpenQA.Selenium;
1111
using OpenQA.Selenium.Support.UI;
1212
using Xunit;

src/Components/test/E2ETest/ServerExecutionTests/ServerSideAppTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
6+
using Microsoft.AspNetCore.E2ETesting;
67
using OpenQA.Selenium;
78
using OpenQA.Selenium.Support.UI;
89
using System;

src/Components/test/E2ETest/ServerExecutionTests/TestSubclasses.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
77
using Microsoft.AspNetCore.Components.E2ETest.Tests;
8+
using Microsoft.AspNetCore.E2ETesting;
89
using Xunit.Abstractions;
910

1011
namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests

src/Components/test/E2ETest/Tests/BinaryHttpClientTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp.HttpClientTest;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using OpenQA.Selenium.Support.UI;
910
using System;

src/Components/test/E2ETest/Tests/BindTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using OpenQA.Selenium.Support.UI;
910
using Xunit;

src/Components/test/E2ETest/Tests/CascadingValueTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using Xunit;
910
using Xunit.Abstractions;

src/Components/test/E2ETest/Tests/ComponentRenderingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using BasicTestApp.HierarchicalImportsTest.Subdir;
1212
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
1313
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
14+
using Microsoft.AspNetCore.E2ETesting;
1415
using OpenQA.Selenium;
1516
using OpenQA.Selenium.Support.UI;
1617
using Xunit;

src/Components/test/E2ETest/Tests/EventBubblingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using System;
910
using Xunit;

src/Components/test/E2ETest/Tests/EventCallbackTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using Xunit;
910
using Xunit.Abstractions;

src/Components/test/E2ETest/Tests/EventTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BasicTestApp;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7+
using Microsoft.AspNetCore.E2ETesting;
78
using OpenQA.Selenium;
89
using OpenQA.Selenium.Interactions;
910
using Xunit;

src/Components/test/E2ETest/Tests/FormsTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using BasicTestApp.FormsTest;
66
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
77
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
8+
using Microsoft.AspNetCore.E2ETesting;
89
using OpenQA.Selenium;
910
using OpenQA.Selenium.Support.UI;
1011
using System;

src/Components/test/E2ETest/Tests/HostedInAspNetTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
55
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
6+
using Microsoft.AspNetCore.E2ETesting;
67
using OpenQA.Selenium;
78
using OpenQA.Selenium.Support.UI;
89
using System;

0 commit comments

Comments
 (0)