From 9f88d16cc4f96dd34fb69f59aba5b59f21c1bb7d Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Tue, 5 Sep 2017 17:33:49 +0100 Subject: [PATCH] Only run browser automation tests if host OS supports it --- .../Helpers/TemplateTestBase.cs | 22 +++++++++++++++++++ test/Templates.Test/SpaTemplateTest.cs | 7 ++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/test/Templates.Test/Helpers/TemplateTestBase.cs b/test/Templates.Test/Helpers/TemplateTestBase.cs index 9efbce8989..c98c2f8652 100644 --- a/test/Templates.Test/Helpers/TemplateTestBase.cs +++ b/test/Templates.Test/Helpers/TemplateTestBase.cs @@ -1,6 +1,8 @@ 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; @@ -12,6 +14,12 @@ 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(); @@ -139,5 +147,19 @@ 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); + } } } diff --git a/test/Templates.Test/SpaTemplateTest.cs b/test/Templates.Test/SpaTemplateTest.cs index e35305b456..b8928815bc 100644 --- a/test/Templates.Test/SpaTemplateTest.cs +++ b/test/Templates.Test/SpaTemplateTest.cs @@ -25,9 +25,12 @@ namespace Templates.Test { aspNetProcess.AssertOk("/"); - using (var browser = aspNetProcess.VisitInBrowser()) + if (EnableBrowserAutomationTesting) { - TestBasicNavigation(browser); + using (var browser = aspNetProcess.VisitInBrowser()) + { + TestBasicNavigation(browser); + } } } }