Skip to content

Run components E2E tests in CI #5158

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 8 commits into from
Jan 8, 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
8 changes: 0 additions & 8 deletions src/Components/build/repo.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
<ProjectsToPack Include="$(RepositoryRoot)blazor\src\*\*.csproj" />
</ItemGroup>

<!--
By default, this excludes the end-to-end tests from the repo-level build command.
The CI will script these directly by passing BlazorAllTests=true
-->
<ItemGroup Condition="'$(BlazorAllTests)'!='true'">
<ExcludeFromTest Include="$(RepositoryRoot)test\Microsoft.AspNetCore.Components.E2ETest\Microsoft.AspNetCore.Components.E2ETest.csproj" />
</ItemGroup>

<ItemGroup>
<DotNetCoreRuntime Include="$(MicrosoftNETCoreAppPackageVersion)" />

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 OpenQA.Selenium;
Expand Down Expand Up @@ -38,7 +38,7 @@ public BrowserFixture()

try
{
var driver = new RemoteWebDriver(opts);
var driver = new RemoteWebDriver(SeleniumStandaloneServer.Instance.Uri, opts);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
Browser = driver;
Logs = new RemoteLogs(driver);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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.Internal;
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure
{
class SeleniumStandaloneServer
{
private static object _instanceCreationLock = new object();
private static SeleniumStandaloneServer _instance;

public Uri Uri { get; }

public static SeleniumStandaloneServer Instance
{
get
{
lock (_instanceCreationLock)
{
if (_instance == null)
{
_instance = new SeleniumStandaloneServer();
}
}

return _instance;
}
}

private SeleniumStandaloneServer()
{
var port = FindAvailablePort();
Uri = new UriBuilder("http", "localhost", port, "/wd/hub").Uri;

var process = Process.Start(new ProcessStartInfo
{
FileName = "npm",
Arguments = $"run selenium-standalone start -- -- -port {port}",
UseShellExecute = true,
});

PollUntilProcessStarted();

AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
{
if (!process.HasExited)
{
process.KillTree(TimeSpan.FromSeconds(10));
process.Dispose();
}
};
}

private void PollUntilProcessStarted()
{
var timeoutAt = DateTime.Now.AddSeconds(30);
Exception lastException = null;
while (true)
{
if (DateTime.Now > timeoutAt)
{
throw new TimeoutException($"The selenium server instance did not start accepting requests at {Uri} before the timeout occurred. The last exception was: {lastException?.ToString() ?? "NULL"}");
}

var httpClient = new HttpClient();
try
{
var timeoutAfter1Second = new CancellationTokenSource(3000);
var response = httpClient.GetAsync(
Uri, timeoutAfter1Second.Token).Result;
response.EnsureSuccessStatusCode();
return;
}
catch (Exception ex)
{
lastException = ex;
}

Thread.Sleep(1000);
}
}

static int FindAvailablePort()
{
var listener = new TcpListener(IPAddress.Loopback, 0);

try
{
listener.Start();
return ((IPEndPoint)listener.LocalEndpoint).Port;
}
finally
{
listener.Stop();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
<DefaultItemExcludes>${DefaultItemExcludes};node_modules\**</DefaultItemExcludes>
<!-- WebDriver is not strong-named signed -->
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<Target Name="EnsureNpmRestored" BeforeTargets="Build" Condition="!Exists('node_modules')">
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec Command="npm ci" />
</Target>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(AspNetCorePackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCorePackageVersion)" />
Expand All @@ -32,4 +38,8 @@
<ProjectReference Include="..\testapps\TestServer\TestServer.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\Shared\Process\ProcessExtensions.cs" Link="Shared\ProcessExtensions.cs" />
</ItemGroup>

</Project>
Loading