Skip to content

Commit 9cb4093

Browse files
committed
Fix for SeleniumServerFactory
1 parent 3adf2b0 commit 9cb4093

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ASP.NET Core/Tests/AspNetCoreTemplate.Web.Tests/SeleniumServerFactory.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
using System.Diagnostics;
55
using System.Linq;
66

7+
using Microsoft.AspNetCore;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.Hosting.Server.Features;
910
using Microsoft.AspNetCore.Mvc.Testing;
1011
using Microsoft.AspNetCore.TestHost;
1112
using Microsoft.Extensions.DependencyInjection;
1213

13-
public class SeleniumServerFactory<TStartup> : WebApplicationFactory<TStartup>
14+
public sealed class SeleniumServerFactory<TStartup> : WebApplicationFactory<TStartup>
1415
where TStartup : class
1516
{
1617
private readonly Process process;
@@ -20,6 +21,7 @@ public class SeleniumServerFactory<TStartup> : WebApplicationFactory<TStartup>
2021
public SeleniumServerFactory()
2122
{
2223
this.ClientOptions.BaseAddress = new Uri("https://localhost"); // will follow redirects by default
24+
this.CreateServer(this.CreateWebHostBuilder());
2325

2426
this.process = new Process
2527
{
@@ -33,11 +35,10 @@ public SeleniumServerFactory()
3335
this.process.Start();
3436
}
3537

36-
public string RootUri { get; set; } // Save this use by tests
38+
public string RootUri { get; set; }
3739

3840
protected override TestServer CreateServer(IWebHostBuilder builder)
3941
{
40-
// Real TCP port
4142
this.host = builder.Build();
4243
this.host.Start();
4344
this.RootUri = this.host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.LastOrDefault(); // Last is https://localhost:5001!
@@ -46,6 +47,13 @@ protected override TestServer CreateServer(IWebHostBuilder builder)
4647
return new TestServer(new WebHostBuilder().UseStartup<FakeStartup>());
4748
}
4849

50+
protected override IWebHostBuilder CreateWebHostBuilder()
51+
{
52+
var builder = WebHost.CreateDefaultBuilder(Array.Empty<string>());
53+
builder.UseStartup<TStartup>();
54+
return builder;
55+
}
56+
4957
protected override void Dispose(bool disposing)
5058
{
5159
base.Dispose(disposing);

ASP.NET Core/Tests/AspNetCoreTemplate.Web.Tests/SeleniumTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public SeleniumTests(SeleniumServerFactory<Startup> server)
1717
this.server = server;
1818
server.CreateClient();
1919
var opts = new ChromeOptions();
20-
opts.AddArgument("--headless"); // Optional, comment this out if you want to SEE the browser window
21-
opts.AddArgument("no-sandbox");
20+
opts.AddArguments("--headless", "--ignore-certificate-errors");
2221
this.browser = new RemoteWebDriver(opts);
2322
}
2423

0 commit comments

Comments
 (0)