Fix tests
This commit is contained in:
parent
70260923ef
commit
d0c73c16d5
|
|
@ -1,10 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Edge;
|
||||
using OpenQA.Selenium.Firefox;
|
||||
|
||||
namespace Templates.Test.Helpers
|
||||
{
|
||||
|
|
@ -14,41 +10,17 @@ namespace Templates.Test.Helpers
|
|||
// Any action will have to be completed in at most 10 seconds.
|
||||
// Providing a smaller value won't improve the speed of the tests in any
|
||||
// significant way and will make them more prone to fail on slower drivers.
|
||||
private const int DefaultMaxWaitTimeInSeconds = 10;
|
||||
internal const int DefaultMaxWaitTimeInSeconds = 10;
|
||||
|
||||
public static bool HostSupportsBrowserAutomation
|
||||
=> string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ASPNETCORE_BROWSER_AUTOMATION_DISABLED")) &&
|
||||
(IsAppVeyor || OSSupportsEdge());
|
||||
(IsAppVeyor || (IsVSTS && RuntimeInformation.OSDescription.Contains("Microsoft Windows")) || 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 || UseFirefox()) ? CreateFirefoxDriver() : CreateEdgeDriver();
|
||||
result.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(DefaultMaxWaitTimeInSeconds);
|
||||
return result;
|
||||
|
||||
bool UseFirefox() => !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ASPNETCORE_BROWSER_AUTOMATION_FIREFOX"));
|
||||
}
|
||||
|
||||
private static IWebDriver CreateEdgeDriver()
|
||||
=> new EdgeDriver(EdgeDriverService.CreateDefaultService(BinDir));
|
||||
|
||||
private static IWebDriver CreateFirefoxDriver()
|
||||
=> new FirefoxDriver(
|
||||
FirefoxDriverService.CreateDefaultService(BinDir),
|
||||
new FirefoxOptions()
|
||||
{
|
||||
AcceptInsecureCertificates = true
|
||||
},
|
||||
TimeSpan.FromSeconds(DefaultMaxWaitTimeInSeconds));
|
||||
|
||||
private static string BinDir
|
||||
=> Path.GetDirectoryName(typeof(WebDriverFactory).Assembly.Location);
|
||||
private static bool IsVSTS
|
||||
=> Environment.GetEnvironmentVariables().Contains("TF_BUILD");
|
||||
|
||||
private static int GetWindowsVersion()
|
||||
{
|
||||
|
|
@ -60,7 +32,7 @@ namespace Templates.Test.Helpers
|
|||
private static bool OSSupportsEdge()
|
||||
{
|
||||
var windowsVersion = GetWindowsVersion();
|
||||
return (windowsVersion >= DefaultMaxWaitTimeInSeconds && windowsVersion < 2000)
|
||||
return (windowsVersion >= 10 && windowsVersion < 2000)
|
||||
|| (windowsVersion >= 2016);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
using Xunit;
|
||||
// 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 Templates.Test.Infrastructure;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
[assembly: AssemblyFixture(typeof(SeleniumServerFixture))]
|
||||
namespace Templates.Test.SpaTemplateTest
|
||||
{
|
||||
public class ReactReduxTemplateTest : SpaTemplateTestBase
|
||||
{
|
||||
public ReactReduxTemplateTest(ITestOutputHelper output) : base(output)
|
||||
public ReactReduxTemplateTest(BrowserFixture browserFixture, ITestOutputHelper output) : base(browserFixture, output)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
// 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 Templates.Test.Infrastructure;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
[assembly: AssemblyFixture(typeof(SeleniumServerFixture))]
|
||||
namespace Templates.Test.SpaTemplateTest
|
||||
{
|
||||
public class ReactTemplateTest : SpaTemplateTestBase
|
||||
{
|
||||
public ReactTemplateTest(BrowserFixture browserFixture, ITestOutputHelper output) : base(browserFixture, output)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReactTemplate_Works_NetCore()
|
||||
=> SpaTemplateImpl(null, "react");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue