Skip to content

Commit 5b4f300

Browse files
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
1 parent efa72d9 commit 5b4f300

File tree

16 files changed

+24
-111
lines changed

16 files changed

+24
-111
lines changed

src/Components/WebAssembly/testassets/HostedInAspNet.Client/wwwroot/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
</head>
77
<body>
88
<app>Loading...</app>
9-
<script src="seleniumworkaround.js"></script>
109
<script src="customJsFileForTests.js"></script>
1110
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
1211

src/Components/WebAssembly/testassets/HostedInAspNet.Client/wwwroot/seleniumworkaround.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Components/WebAssembly/testassets/Wasm.Authentication.Client/wwwroot/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<a class="dismiss">🗙</a>
1919
</div>
2020

21-
<script src="seleniumworkaround.js"></script>
2221
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
2322
<script src="_framework/blazor.webassembly.js"></script>
2423
</body>

src/Components/WebAssembly/testassets/Wasm.Authentication.Client/wwwroot/seleniumworkaround.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Components/test/E2ETest/ServerExecutionTests/MultipleRootComponentsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override async Task InitializeAsync()
4343
}
4444
}
4545

46-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
46+
[Fact]
4747
public void DoesNotStartMultipleConnections()
4848
{
4949
Navigate("/multiple-components");

src/Components/test/E2ETest/ServerExecutionTests/ServerReconnectionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void RendersContinueAfterReconnect()
7878
Browser.False(() => Browser.Exists(selector).Text == currentValue);
7979
}
8080

81-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
81+
[Fact]
8282
public void ErrorsStopTheRenderingProcess()
8383
{
8484
Browser.Exists(By.Id("cause-error")).Click();

src/Components/test/E2ETest/Tests/WebAssemblyAuthenticationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public void LoggedInUser_OnTheIdP_CanLogInSilently()
306306
ValidateLoggedIn(userName);
307307
}
308308

309-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
309+
[Fact]
310310
public void CanNotRedirect_To_External_ReturnUrl()
311311
{
312312
Browser.Navigate().GoToUrl(new Uri(new Uri(Browser.Url), "/authentication/login?returnUrl=https%3A%2F%2Fwww.bing.com").AbsoluteUri);

src/Components/test/E2ETest/Tests/WebAssemblyICUShardingTest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Globalization;
6+
using System.Linq;
57
using GlobalizationWasmApp;
68
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
79
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@@ -107,11 +109,10 @@ public void LoadingApp_DynamicallySetLanguageThrows()
107109
var errorUi = Browser.Exists(By.Id("blazor-error-ui"));
108110
Browser.Equal("block", () => errorUi.GetCssValue("display"));
109111

110-
// Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803"
111-
// var expected = "This application's globalization settings requires using the combined globalization data file.";
112-
// var logs = Browser.GetBrowserLogs(LogLevel.Severe).Select(l => l.Message);
113-
// Assert.True(logs.Any(l => l.Contains(expected)),
114-
// $"Expected to see globalization error message in the browser logs: {string.Join(Environment.NewLine, logs)}.");
112+
var expected = "Blazor detected a change in the application's culture that is not supported with the current project configuration.";
113+
var logs = Browser.GetBrowserLogs(LogLevel.Severe).Select(l => l.Message);
114+
Assert.True(logs.Any(l => l.Contains(expected)),
115+
$"Expected to see globalization error message in the browser logs: {string.Join(Environment.NewLine, logs)}.");
115116
}
116117

117118
private void Initialize(CultureInfo culture)

src/Components/test/E2ETest/Tests/WebAssemblyLazyLoadTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void CanLazyLoadAssemblyWithRoutes()
108108
Assert.True(renderedElement.Displayed);
109109
}
110110

111-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
111+
[Fact]
112112
public void ThrowsErrorForUnavailableAssemblies()
113113
{
114114
// Navigate to a page with lazy loaded assemblies for the first time

src/Components/test/E2ETest/Tests/WebAssemblyLoggingTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override void InitializeAsyncCore()
3232
Assert.Equal("none", errorUi.GetCssValue("display"));
3333
}
3434

35-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
35+
[Fact]
3636
public void LogsSimpleExceptionsUsingLogger()
3737
{
3838
Browser.Exists(By.Id("throw-simple-exception")).Click();
@@ -44,7 +44,7 @@ public void LogsSimpleExceptionsUsingLogger()
4444
"at BasicTestApp.ErrorComponent.ThrowSimple");
4545
}
4646

47-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
47+
[Fact]
4848
public void LogsInnerExceptionsUsingLogger()
4949
{
5050
Browser.Exists(By.Id("throw-inner-exception")).Click();
@@ -57,7 +57,7 @@ public void LogsInnerExceptionsUsingLogger()
5757
"at BasicTestApp.ErrorComponent.ThrowInner");
5858
}
5959

60-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
60+
[Fact]
6161
public void LogsAggregateExceptionsUsingLogger()
6262
{
6363
Browser.Exists(By.Id("throw-aggregate-exception")).Click();
@@ -72,7 +72,7 @@ public void LogsAggregateExceptionsUsingLogger()
7272
"System.InvalidTimeZoneException: Aggregate exception 3");
7373
}
7474

75-
[Fact(Skip = "Browser logs cannot be retrieved: https://github.com/dotnet/aspnetcore/issues/25803")]
75+
[Fact]
7676
public void LogsUsingCustomLogger()
7777
{
7878
Browser.MountTestComponent<LoggingComponent>();

src/Components/test/testassets/BasicTestApp/wwwroot/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
</div>
2727

2828
<!-- Used for specific test cases -->
29-
<script src="js/seleniumworkaround.js"></script>
3029
<script src="js/jsinteroptests.js"></script>
3130
<script src="js/renderattributestest.js"></script>
3231
<script src="js/webComponentPerformingJsInterop.js"></script>
@@ -49,8 +48,6 @@
4948
</script>
5049
<script src="_framework/blazor.webassembly.js"></script>
5150

52-
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
53-
5451
<!-- Used by ExternalContentPackage -->
5552
<script src="_content/TestContentPackage/prompt.js"></script>
5653
</body>

src/Components/test/testassets/BasicTestApp/wwwroot/js/seleniumworkaround.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Components/test/testassets/TestServer/Pages/PrerenderedHost.cshtml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
<script src="_framework/blazor.server.js" autostart="false"></script>
2222

23-
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
24-
2523
<script>
2624
// Used by InteropOnInitializationComponent
2725
function setElementValue(element, newValue) {

src/Components/test/testassets/TestServer/Pages/_ServerHost.cshtml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
<script src="_framework/blazor.server.js"></script>
4444

45-
<script src="_content/Microsoft.AspNetCore.Components.Web.Extensions/headManager.js"></script>
46-
4745
<!-- Used by ExternalContentPackage -->
4846
<script src="_content/TestContentPackage/prompt.js"></script>
4947
<script>

src/Shared/E2ETesting/BrowserFixture.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private async Task DeleteBrowserUserProfileDirectoriesAsync()
183183
// Additionally, if we think the selenium server has become irresponsive, we could spin up
184184
// replace the current selenium server instance and let a new instance take over for the
185185
// remaining tests.
186-
var driver = new RemoteWebDriver(
186+
var driver = new RemoteWebDriverWithLogs(
187187
instance.Uri,
188188
opts.ToCapabilities(),
189189
TimeSpan.FromSeconds(60).Add(TimeSpan.FromSeconds(attempt * 60)));
@@ -336,5 +336,14 @@ private string UserProfileDirectory(string context)
336336

337337
throw new InvalidOperationException("Couldn't create a SauceLabs remote driver client.");
338338
}
339+
340+
// This is a workaround for https://github.com/SeleniumHQ/selenium/issues/8229
341+
private class RemoteWebDriverWithLogs : RemoteWebDriver, ISupportsLogs
342+
{
343+
public RemoteWebDriverWithLogs(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
344+
: base(remoteAddress, desiredCapabilities, commandTimeout)
345+
{
346+
}
347+
}
339348
}
340349
}

src/Shared/E2ETesting/WaitAssert.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ private static TResult WaitAssertCore<TResult>(IWebDriver driver, Func<TResult>
121121
var fileId = $"{Guid.NewGuid():N}.png";
122122
var screenShotPath = Path.Combine(Path.GetFullPath(E2ETestOptions.Instance.ScreenShotsPath), fileId);
123123
var errors = driver.GetBrowserLogs(LogLevel.All).Select(c => c.ToString()).ToList();
124-
if (errors.Count == 0)
125-
{
126-
// Workaround for selenium bug https://github.com/SeleniumHQ/selenium/issues/8229. Getting log does
127-
// not work. However some of our test apps provide a mechnanism to read the logs. Try that.
128-
129-
var logs = (IReadOnlyCollection<object>)((IJavaScriptExecutor)driver).ExecuteScript(
130-
"return window.getBrowserLogs && window.getBrowserLogs() || []");
131-
132-
errors = logs.Select(l => l.ToString()).ToList();
133-
}
134124

135125
TakeScreenShot(driver, screenShotPath);
136126
var exceptionInfo = lastException != null ? ExceptionDispatchInfo.Capture(lastException) :

0 commit comments

Comments
 (0)