Fix E2E test use of logs (#27114) (#27166)

* Restore support for logs in E2E tests. Fixes #25803

* Revert earlier workaround

* Update message in assertion

* Remove redundant script references
This commit is contained in:
Steve Sanderson 2021-02-11 21:30:17 +00:00 committed by GitHub
parent efa72d92c3
commit 5b4f3003af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 24 additions and 111 deletions

View File

@ -6,7 +6,6 @@
</head>
<body>
<app>Loading...</app>
<script src="seleniumworkaround.js"></script>
<script src="customJsFileForTests.js"></script>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>

View File

@ -1,26 +0,0 @@
(function () {
// Note: there are multiple copies of this file throughout the repo. If you're editing it, please look for
// other seleniumworkaround.js files and keep them all in sync.
const logs = [];
const defaultLog = console.log;
console.log = function () {
defaultLog.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultError = console.error;
console.error = function () {
defaultError.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultWarn = console.warn;
console.warn = function () {
defaultWarn.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
window.getBrowserLogs = () => logs;
})();

View File

@ -18,7 +18,6 @@
<a class="dismiss">🗙</a>
</div>
<script src="seleniumworkaround.js"></script>
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
</body>

View File

@ -1,26 +0,0 @@
(function () {
// Note: there are multiple copies of this file throughout the repo. If you're editing it, please look for
// other seleniumworkaround.js files and keep them all in sync.
const logs = [];
const defaultLog = console.log;
console.log = function () {
defaultLog.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultError = console.error;
console.error = function () {
defaultError.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultWarn = console.warn;
console.warn = function () {
defaultWarn.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
window.getBrowserLogs = () => logs;
})();

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
}
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void DoesNotStartMultipleConnections()
{
Navigate("/multiple-components");

View File

@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
Browser.False(() => Browser.Exists(selector).Text == currentValue);
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void ErrorsStopTheRenderingProcess()
{
Browser.Exists(By.Id("cause-error")).Click();

View File

@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
ValidateLoggedIn(userName);
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void CanNotRedirect_To_External_ReturnUrl()
{
Browser.Navigate().GoToUrl(new Uri(new Uri(Browser.Url), "/authentication/login?returnUrl=https%3A%2F%2Fwww.bing.com").AbsoluteUri);

View File

@ -1,7 +1,9 @@
// 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 System;
using System.Globalization;
using System.Linq;
using GlobalizationWasmApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@ -107,11 +109,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
var errorUi = Browser.Exists(By.Id("blazor-error-ui"));
Browser.Equal("block", () => errorUi.GetCssValue("display"));
// Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803"
// var expected = "This application's globalization settings requires using the combined globalization data file.";
// var logs = Browser.GetBrowserLogs(LogLevel.Severe).Select(l => l.Message);
// Assert.True(logs.Any(l => l.Contains(expected)),
// $"Expected to see globalization error message in the browser logs: {string.Join(Environment.NewLine, logs)}.");
var expected = "Blazor detected a change in the application's culture that is not supported with the current project configuration.";
var logs = Browser.GetBrowserLogs(LogLevel.Severe).Select(l => l.Message);
Assert.True(logs.Any(l => l.Contains(expected)),
$"Expected to see globalization error message in the browser logs: {string.Join(Environment.NewLine, logs)}.");
}
private void Initialize(CultureInfo culture)

View File

@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Assert.True(renderedElement.Displayed);
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void ThrowsErrorForUnavailableAssemblies()
{
// Navigate to a page with lazy loaded assemblies for the first time

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Assert.Equal("none", errorUi.GetCssValue("display"));
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void LogsSimpleExceptionsUsingLogger()
{
Browser.Exists(By.Id("throw-simple-exception")).Click();
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
"at BasicTestApp.ErrorComponent.ThrowSimple");
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void LogsInnerExceptionsUsingLogger()
{
Browser.Exists(By.Id("throw-inner-exception")).Click();
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
"at BasicTestApp.ErrorComponent.ThrowInner");
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void LogsAggregateExceptionsUsingLogger()
{
Browser.Exists(By.Id("throw-aggregate-exception")).Click();
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
"System.InvalidTimeZoneException: Aggregate exception 3");
}
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void LogsUsingCustomLogger()
{
Browser.MountTestComponent<LoggingComponent>();

View File

@ -26,7 +26,6 @@
</div>
<!-- Used for specific test cases -->
<script src="js/seleniumworkaround.js"></script>
<script src="js/jsinteroptests.js"></script>
<script src="js/renderattributestest.js"></script>
<script src="js/webComponentPerformingJsInterop.js"></script>
@ -49,8 +48,6 @@
</script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
<!-- Used by ExternalContentPackage -->
<script src="_content/TestContentPackage/prompt.js"></script>
</body>

View File

@ -1,26 +0,0 @@
(function () {
// Note: there are multiple copies of this file throughout the repo. If you're editing it, please look for
// other seleniumworkaround.js files and keep them all in sync.
const logs = [];
const defaultLog = console.log;
console.log = function () {
defaultLog.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultError = console.error;
console.error = function () {
defaultError.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
const defaultWarn = console.warn;
console.warn = function () {
defaultWarn.apply(console, arguments);
logs.push(Array.from(arguments).join(' '));
}
window.getBrowserLogs = () => logs;
})();

View File

@ -20,8 +20,6 @@
<script src="_framework/blazor.server.js" autostart="false"></script>
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
<script>
// Used by InteropOnInitializationComponent
function setElementValue(element, newValue) {

View File

@ -42,8 +42,6 @@
<script src="_framework/blazor.server.js"></script>
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
<!-- Used by ExternalContentPackage -->
<script src="_content/TestContentPackage/prompt.js"></script>
<script>

View File

@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.E2ETesting
// Additionally, if we think the selenium server has become irresponsive, we could spin up
// replace the current selenium server instance and let a new instance take over for the
// remaining tests.
var driver = new RemoteWebDriver(
var driver = new RemoteWebDriverWithLogs(
instance.Uri,
opts.ToCapabilities(),
TimeSpan.FromSeconds(60).Add(TimeSpan.FromSeconds(attempt * 60)));
@ -336,5 +336,14 @@ namespace Microsoft.AspNetCore.E2ETesting
throw new InvalidOperationException("Couldn't create a SauceLabs remote driver client.");
}
// This is a workaround for https://github.com/SeleniumHQ/selenium/issues/8229
private class RemoteWebDriverWithLogs : RemoteWebDriver, ISupportsLogs
{
public RemoteWebDriverWithLogs(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(remoteAddress, desiredCapabilities, commandTimeout)
{
}
}
}
}

View File

@ -121,16 +121,6 @@ namespace Microsoft.AspNetCore.E2ETesting
var fileId = $"{Guid.NewGuid():N}.png";
var screenShotPath = Path.Combine(Path.GetFullPath(E2ETestOptions.Instance.ScreenShotsPath), fileId);
var errors = driver.GetBrowserLogs(LogLevel.All).Select(c => c.ToString()).ToList();
if (errors.Count == 0)
{
// Workaround for selenium bug https://github.com/SeleniumHQ/selenium/issues/8229. Getting log does
// not work. However some of our test apps provide a mechnanism to read the logs. Try that.
var logs = (IReadOnlyCollection<object>)((IJavaScriptExecutor)driver).ExecuteScript(
"return window.getBrowserLogs && window.getBrowserLogs() || []");
errors = logs.Select(l => l.ToString()).ToList();
}
TakeScreenShot(driver, screenShotPath);
var exceptionInfo = lastException != null ? ExceptionDispatchInfo.Capture(lastException) :