Skip to content

Commit 0e5d7ef

Browse files
authored
Attempt to read the logs from the browser (#26289)
* Attempt to read the logs from the browser Seleniunm currently does not return log messages (See SeleniumHQ/selenium#8229). This making figuring out blazor WASM test failures a lot harder. This change adds some JS to the test apps to read the console output. * WIP
1 parent 90f4cda commit 0e5d7ef

File tree

19 files changed

+118
-42
lines changed

19 files changed

+118
-42
lines changed

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

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function () {
2+
// Note: there are multiple copies of this file throughout the repo. If you're editing it, please look for
3+
// other seleniumworkaround.js files and keep them all in sync.
4+
const logs = [];
5+
6+
const defaultLog = console.log;
7+
console.log = function () {
8+
defaultLog.apply(console, arguments);
9+
logs.push(Array.from(arguments).join(' '));
10+
}
11+
12+
const defaultError = console.error;
13+
console.error = function () {
14+
defaultError.apply(console, arguments);
15+
logs.push(Array.from(arguments).join(' '));
16+
}
17+
18+
const defaultWarn = console.warn;
19+
console.warn = function () {
20+
defaultWarn.apply(console, arguments);
21+
logs.push(Array.from(arguments).join(' '));
22+
}
23+
24+
window.getBrowserLogs = () => logs;
25+
})();
26+

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<a href="" class="reload">Reload</a>
1818
<a class="dismiss">🗙</a>
1919
</div>
20+
21+
<script src="seleniumworkaround.js"></script>
2022
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
2123
<script src="_framework/blazor.webassembly.js"></script>
2224
</body>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function () {
2+
// Note: there are multiple copies of this file throughout the repo. If you're editing it, please look for
3+
// other seleniumworkaround.js files and keep them all in sync.
4+
const logs = [];
5+
6+
const defaultLog = console.log;
7+
console.log = function () {
8+
defaultLog.apply(console, arguments);
9+
logs.push(Array.from(arguments).join(' '));
10+
}
11+
12+
const defaultError = console.error;
13+
console.error = function () {
14+
defaultError.apply(console, arguments);
15+
logs.push(Array.from(arguments).join(' '));
16+
}
17+
18+
const defaultWarn = console.warn;
19+
console.warn = function () {
20+
defaultWarn.apply(console, arguments);
21+
logs.push(Array.from(arguments).join(' '));
22+
}
23+
24+
window.getBrowserLogs = () => logs;
25+
})();
26+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ private void PerformReconnection()
6262
((IJavaScriptExecutor)Browser).ExecuteScript("Blazor._internal.forceCloseConnection()");
6363

6464
// Wait until the reconnection dialog has been shown but is now hidden
65-
new WebDriverWait(Browser, TimeSpan.FromSeconds(10))
66-
.Until(driver => driver.FindElement(By.Id("components-reconnect-modal"))?.GetCssValue("display") == "none");
65+
var reconnectModel = Browser.Exists(By.Id("components-reconnect-modal"));
66+
Browser.Equal("none", () => reconnectModel.GetCssValue("display"));
6767
}
6868
}
6969
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public void DotNetExceptionDetailsAreNotLoggedByDefault()
4848
var interopButton = Browser.FindElement(By.Id("btn-interop"));
4949
interopButton.Click();
5050

51-
var wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(10))
52-
.Until(d => d.FindElement(By.Id("done-with-interop")));
51+
Browser.Exists(By.Id("done-with-interop"));
5352

5453
foreach (var expectedValue in expectedValues)
5554
{

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using BasicTestApp;
65
using BasicTestApp.HttpClientTest;
76
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
87
using Microsoft.AspNetCore.E2ETesting;
98
using Microsoft.AspNetCore.Testing;
109
using OpenQA.Selenium;
11-
using OpenQA.Selenium.Support.UI;
1210
using TestServer;
1311
using Xunit;
1412
using Xunit.Abstractions;
@@ -61,9 +59,7 @@ private void IssueRequest(string relativeUri)
6159

6260
_appElement.FindElement(By.Id("send-request")).Click();
6361

64-
new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
65-
driver => driver.FindElement(By.Id("response-status")) != null);
66-
_responseStatus = _appElement.FindElement(By.Id("response-status"));
62+
_responseStatus = Browser.Exists(By.Id("response-status"));
6763
_responseStatusText = _appElement.FindElement(By.Id("response-status-text"));
6864
_testOutcome = _appElement.FindElement(By.Id("test-outcome"));
6965
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ private IReadOnlyCollection<string> GetAndClearRequestedPaths()
148148

149149
private void WaitUntilLoaded()
150150
{
151-
new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
152-
driver => driver.FindElement(By.TagName("h1")).Text == "Hello, world!");
151+
var element = Browser.Exists(By.TagName("h1"));
152+
Browser.Equal("Hello, world!", () => element.Text);
153153
}
154154
}
155155
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ public void MapFallbackToClientSideBlazor_AssemblyPath_Pattern_FilePath()
6161
Assert.NotNull(Browser.FindElement(By.Id("test-selector")));
6262
}
6363

64-
6564
private void WaitUntilLoaded()
6665
{
67-
new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
68-
driver => driver.FindElement(By.TagName("app")).Text != "Loading...");
66+
var app = Browser.Exists(By.TagName("app"));
67+
Browser.NotEqual("Loading...", () => app.Text);
6968
}
7069
}
7170
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public void ServesStaticAssetsFromClientAppWebRoot()
4848

4949
private void WaitUntilLoaded()
5050
{
51-
new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
52-
driver => driver.FindElement(By.TagName("app")).Text != "Loading...");
51+
var app = Browser.Exists(By.TagName("app"));
52+
Browser.NotEqual("Loading...", () => app.Text);
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)