On AppVeyor, must use Firefox (not Edge) for Selenium tests
This commit is contained in:
parent
4a4dcbab3d
commit
7e8d48cd80
|
|
@ -1,12 +1,10 @@
|
|||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Edge;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace Templates.Test.Helpers
|
||||
|
|
@ -73,8 +71,7 @@ namespace Templates.Test.Helpers
|
|||
|
||||
public IWebDriver VisitInBrowser()
|
||||
{
|
||||
var driver = new EdgeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
|
||||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
|
||||
var driver = WebDriverFactory.CreateWebDriver();
|
||||
driver.Navigate().GoToUrl(_listeningUri);
|
||||
return driver;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using Templates.Test.Helpers;
|
||||
using Xunit;
|
||||
|
|
@ -14,12 +12,6 @@ namespace Templates.Test
|
|||
protected string ProjectName { get; set; }
|
||||
protected string TemplateOutputDir { get; private set; }
|
||||
|
||||
// The tests use EdgeDriver because InternetExplorerDriver is flaky and
|
||||
// ChromeDriver is very slow (plus, Chrome might not be on CI machines).
|
||||
// This limits us to running the browser automation tests on Windows 10+.
|
||||
protected bool EnableBrowserAutomationTesting
|
||||
=> OSSupportsEdge();
|
||||
|
||||
static TemplateTestBase()
|
||||
{
|
||||
TemplatePackageInstaller.ReinstallTemplatePackages();
|
||||
|
|
@ -147,19 +139,5 @@ namespace Templates.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetWindowsVersion()
|
||||
{
|
||||
var osDescription = RuntimeInformation.OSDescription;
|
||||
var windowsVersion = Regex.Match(osDescription, "^Microsoft Windows (\\d+)\\..*");
|
||||
return windowsVersion.Success ? int.Parse(windowsVersion.Groups[1].Value) : -1;
|
||||
}
|
||||
|
||||
private static bool OSSupportsEdge()
|
||||
{
|
||||
var windowsVersion = GetWindowsVersion();
|
||||
return (windowsVersion >= 10 && windowsVersion < 2000)
|
||||
|| (windowsVersion >= 2016);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Edge;
|
||||
using OpenQA.Selenium.Firefox;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Templates.Test.Helpers
|
||||
{
|
||||
public static class WebDriverFactory
|
||||
{
|
||||
public static bool HostSupportsBrowserAutomation
|
||||
=> IsAppVeyor || OSSupportsEdge();
|
||||
|
||||
private static bool IsAppVeyor
|
||||
=> Environment.GetEnvironmentVariables().Contains("APPVEYOR");
|
||||
|
||||
public static IWebDriver CreateWebDriver()
|
||||
{
|
||||
// Where possible, it's preferable to use Edge because it's
|
||||
// far faster to automate than Chrome/Firefox. But on AppVeyor
|
||||
// only Firefox is available.
|
||||
var result = IsAppVeyor ? new FirefoxDriver() : (IWebDriver)new EdgeDriver();
|
||||
result.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetWindowsVersion()
|
||||
{
|
||||
var osDescription = RuntimeInformation.OSDescription;
|
||||
var windowsVersion = Regex.Match(osDescription, "^Microsoft Windows (\\d+)\\..*");
|
||||
return windowsVersion.Success ? int.Parse(windowsVersion.Groups[1].Value) : -1;
|
||||
}
|
||||
|
||||
private static bool OSSupportsEdge()
|
||||
{
|
||||
var windowsVersion = GetWindowsVersion();
|
||||
return (windowsVersion >= 10 && windowsVersion < 2000)
|
||||
|| (windowsVersion >= 2016);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ namespace Templates.Test
|
|||
{
|
||||
aspNetProcess.AssertOk("/");
|
||||
|
||||
if (EnableBrowserAutomationTesting)
|
||||
if (WebDriverFactory.HostSupportsBrowserAutomation)
|
||||
{
|
||||
Console.WriteLine("Starting browser automation tests...");
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@
|
|||
<PackageReference Include="System.Security.Permissions" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Internal.AspNetCore.Sdk" PrivateAssets="All" />
|
||||
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="15.15063.0" NoWarn="KRB4002" />
|
||||
<PackageReference Include="Selenium.Support" Version="3.4.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Selenium.Firefox.WebDriver" Version="0.18.0" NoWarn="KRB4002" />
|
||||
<PackageReference Include="Selenium.Support" Version="3.4.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Selenium.WebDriver" Version="3.4.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="15.15063.0" NoWarn="KRB4002" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.analyzers" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue