Skip to content

[Templating][Components] Unify and improve E2E testing infrastructure #8188

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
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .azure/pipelines/jobs/default-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ jobs:
- ${{ if and(eq(parameters.installJdk, 'true'), eq(parameters.agentOs, 'Windows')) }}:
- powershell: ./eng/scripts/InstallJdk.ps1 '11.0.1'
displayName: Install JDK 11
- powershell: Write-Host "##vso[task.prependpath]$env:JAVA_HOME\bin"
displayName: Prepend JAVA bin folder to the PATH.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change $env:Path globally. Java is only needed in a few places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is super problematic? It's only building on the CI (so local builds aren't affected) and goes away once the build finishes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not "super problematic" but it's a break from how the build currently works and broader than seemed necessary. If we go this route (rather than, say, creating a yarn.bat script), should clean up the Gradlew script and anything else that updates $env:Path for Java on Windows.

- powershell: ./eng/scripts/InstallGoogleChrome.ps1
displayName: Install chrome
- ${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.agentOs, 'Windows'), eq(parameters.codeSign, 'true')) }}:
- task: MicroBuildSigningPlugin@1
displayName: Install MicroBuild Signing plugin
Expand Down
4 changes: 4 additions & 0 deletions eng/scripts/InstallGoogleChrome.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$InstallerPath = "$env:Temp\chrome_installer.exe";
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $InstallerPath;
Start-Process -FilePath $InstallerPath -Args "/silent /install" -Verb RunAs -Wait;
Remove-Item $InstallerPath
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
Expand Down
60 changes: 0 additions & 60 deletions src/Components/test/E2ETest/Infrastructure/BrowserFixture.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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;
Expand All @@ -24,7 +24,7 @@ protected override IWebHost CreateWebHost()
}

var sampleSitePath = FindSampleOrTestSitePath(
BuildWebHostMethod.Method.DeclaringType.Assembly.GetName().Name);
BuildWebHostMethod.Method.DeclaringType.Assembly.FullName);

return BuildWebHostMethod(new[]
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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.AspNetCore.Hosting;
Expand All @@ -16,7 +16,7 @@ public class DevHostServerFixture<TProgram> : WebHostServerFixture
protected override IWebHost CreateWebHost()
{
ContentRoot = FindSampleOrTestSitePath(
typeof(TProgram).Assembly.GetName().Name);
typeof(TProgram).Assembly.FullName);

var args = new List<string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

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

protected abstract string StartAndGetRootUri();

protected static string FindSolutionDir()
{
return FindClosestDirectoryContaining(
"Components.sln",
Path.GetDirectoryName(typeof(ServerFixture).Assembly.Location));
}

private static Dictionary<string, string> FindProjects()
{
var solutionDir = FindSolutionDir();

var testAssetsDirectories = new[]
{
Path.Combine(solutionDir, "test", "testassets"),
Path.Combine(solutionDir, "blazor", "testassets"),
};

return testAssetsDirectories
.SelectMany(d => new DirectoryInfo(d).EnumerateDirectories())
.ToDictionary(d => d.Name, d => d.FullName);
return typeof(ServerFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.Where(m => m.Key.StartsWith("TestAssemblyApplication["))
.ToDictionary(m =>
m.Key.Replace("TestAssemblyApplication", "").TrimStart('[').TrimEnd(']'),
m => m.Value);
}

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

private static string FindClosestDirectoryContaining(
string filename,
string startDirectory)
{
var dir = startDirectory;
while (true)
{
if (File.Exists(Path.Combine(dir, filename)))
{
return dir;
}

dir = Directory.GetParent(dir)?.FullName;
if (string.IsNullOrEmpty(dir))
{
throw new FileNotFoundException(
$"Could not locate a file called '{filename}' in " +
$"directory '{startDirectory}' or any parent directory.");
}
}
}

protected static void RunInBackgroundThread(Action action)
{
var isDone = new ManualResetEvent(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using System;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Shared testing infrastructure for running E2E tests using selenium -->
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.props" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import and the targets import below is all that's needed to bring in Selenium E2E tests


<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);node_modules\**</DefaultItemExcludes>
<!-- WebDriver is not strong-named signed -->
<SignAssembly>false</SignAssembly>
<TestGroupName>Components.E2ETests</TestGroupName>

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

<!-- Version of this SDK is set in global.json -->
<Sdk Name="Yarn.MSBuild" />

<Target Name="EnsureNodeJSRestored" BeforeTargets="Build" Condition="'$(BlazorAllTests)'=='true'">
<Message Text="Running yarn install on $(MSBuildProjectFile)" Importance="High" />
<Yarn Command="install" />
</Target>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Hosting" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
<Reference Include="Selenium.Support" />
<Reference Include="Selenium.WebDriver" />
</ItemGroup>

<ItemGroup>
Expand All @@ -48,4 +39,7 @@
<ProjectReference Include="..\testassets\TestServer\TestServer.csproj" />
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System;
using BasicTestApp;
using ComponentsApp.App.Pages;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.Components.E2ETest.Tests;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.Components.E2ETest.Tests;
using Microsoft.AspNetCore.E2ETesting;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/BinaryHttpClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp.HttpClientTest;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/BindTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Xunit;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/CascadingValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using BasicTestApp.HierarchicalImportsTest.Subdir;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Xunit;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/EventBubblingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using System;
using Xunit;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/EventCallbackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using Xunit;
using Xunit.Abstractions;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/EventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using Xunit;
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/E2ETest/Tests/FormsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BasicTestApp.FormsTest;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
Expand Down
3 changes: 2 additions & 1 deletion src/Components/test/E2ETest/Tests/HostedInAspNetTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
Expand Down
Loading