Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E2E test use of logs #27114

Merged
merged 4 commits into from Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -307,7 +307,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 @@ -48,8 +47,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 @@ -41,8 +41,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 @@ -187,7 +187,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 @@ -342,5 +342,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was easy

{
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