Skip to content

Commit

Permalink
Fix E2E test use of logs (#27114) (#27166)
Browse files Browse the repository at this point in the history
* Restore support for logs in E2E tests. Fixes #25803

* Revert earlier workaround

* Update message in assertion

* Remove redundant script references
  • Loading branch information
SteveSandersonMS committed Feb 11, 2021
1 parent efa72d9 commit 5b4f300
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 111 deletions.
Expand Up @@ -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>

Expand Down

This file was deleted.

Expand Up @@ -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>
Expand Down

This file was deleted.

Expand Up @@ -43,7 +43,7 @@ public override async Task InitializeAsync()
}
}

[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
[Fact]
public void DoesNotStartMultipleConnections()
{
Navigate("/multiple-components");
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void RendersContinueAfterReconnect()
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();
Expand Down
Expand Up @@ -306,7 +306,7 @@ public void LoggedInUser_OnTheIdP_CanLogInSilently()
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);
Expand Down
11 changes: 6 additions & 5 deletions src/Components/test/E2ETest/Tests/WebAssemblyICUShardingTest.cs
@@ -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;
Expand Down Expand Up @@ -107,11 +109,10 @@ public void LoadingApp_DynamicallySetLanguageThrows()
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)
Expand Down
Expand Up @@ -108,7 +108,7 @@ public void CanLazyLoadAssemblyWithRoutes()
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
Expand Down
8 changes: 4 additions & 4 deletions src/Components/test/E2ETest/Tests/WebAssemblyLoggingTest.cs
Expand Up @@ -32,7 +32,7 @@ protected override void InitializeAsyncCore()
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();
Expand All @@ -44,7 +44,7 @@ public void LogsSimpleExceptionsUsingLogger()
"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();
Expand All @@ -57,7 +57,7 @@ public void LogsInnerExceptionsUsingLogger()
"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();
Expand All @@ -72,7 +72,7 @@ public void LogsAggregateExceptionsUsingLogger()
"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>();
Expand Down
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

This file was deleted.

Expand Up @@ -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) {
Expand Down
Expand Up @@ -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>
Expand Down
11 changes: 10 additions & 1 deletion src/Shared/E2ETesting/BrowserFixture.cs
Expand Up @@ -183,7 +183,7 @@ private async Task<(IWebDriver browser, ILogs log)> CreateBrowserAsync(string co
// 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)));
Expand Down Expand Up @@ -336,5 +336,14 @@ private async Task<(IWebDriver browser, ILogs log)> CreateSauceBrowserAsync(stri

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)
{
}
}
}
}
10 changes: 0 additions & 10 deletions src/Shared/E2ETesting/WaitAssert.cs
Expand Up @@ -121,16 +121,6 @@ private static TResult WaitAssertCore<TResult>(IWebDriver driver, Func<TResult>
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) :
Expand Down

0 comments on commit 5b4f300

Please sign in to comment.