Skip to content

Commit e85398d

Browse files
authored
Merge branch 'trunk' into py-bidi-input
2 parents 152398f + 229dbde commit e85398d

File tree

35 files changed

+2579
-1144
lines changed

35 files changed

+2579
-1144
lines changed

common/repositories.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ js_library(
5050

5151
http_archive(
5252
name = "linux_beta_firefox",
53-
url = "https://ftp.mozilla.org/pub/firefox/releases/142.0b8/linux-x86_64/en-US/firefox-142.0b8.tar.xz",
54-
sha256 = "52c7c24dcc1258c9cd43c7b070def0a93bae58d2f5d077d11a7979307857e5c2",
53+
url = "https://ftp.mozilla.org/pub/firefox/releases/142.0b9/linux-x86_64/en-US/firefox-142.0b9.tar.xz",
54+
sha256 = "0e230f54a1d933df55e0d730c7d774437e60b5fdcbd74401f5da69bce184c30b",
5555
build_file_content = """
5656
load("@aspect_rules_js//js:defs.bzl", "js_library")
5757
package(default_visibility = ["//visibility:public"])
@@ -72,8 +72,8 @@ js_library(
7272

7373
dmg_archive(
7474
name = "mac_beta_firefox",
75-
url = "https://ftp.mozilla.org/pub/firefox/releases/142.0b8/mac/en-US/Firefox%20142.0b8.dmg",
76-
sha256 = "74c20a61fcc05fd69427f370a6a97ab660615299ef254d4cfaa617ec095dba98",
75+
url = "https://ftp.mozilla.org/pub/firefox/releases/142.0b9/mac/en-US/Firefox%20142.0b9.dmg",
76+
sha256 = "529509a53278d8cbd482fa8ef95ac243b33c6cc4acc7924c15f6ce3f59c64bbf",
7777
build_file_content = """
7878
load("@aspect_rules_js//js:defs.bzl", "js_library")
7979
package(default_visibility = ["//visibility:public"])
@@ -165,8 +165,8 @@ js_library(
165165

166166
http_archive(
167167
name = "linux_edgedriver",
168-
url = "https://msedgedriver.microsoft.com/138.0.3351.121/edgedriver_linux64.zip",
169-
sha256 = "1a0bed812b1b84f1093fa1e759cae2a210481620cd9ea3cb91dc2a60e0b21e4d",
168+
url = "https://msedgedriver.microsoft.com/139.0.3405.86/edgedriver_linux64.zip",
169+
sha256 = "49ce29de50f9ac418a3a2416708a5563215b8412b27d3e505f3c859fc6ffba12",
170170
build_file_content = """
171171
load("@aspect_rules_js//js:defs.bzl", "js_library")
172172
package(default_visibility = ["//visibility:public"])
@@ -182,8 +182,8 @@ js_library(
182182

183183
http_archive(
184184
name = "mac_edgedriver",
185-
url = "https://msedgedriver.microsoft.com/138.0.3351.121/edgedriver_mac64.zip",
186-
sha256 = "96b648865de254ae5db7008676340b16476e39b0b90c2da71964c14cb53a0195",
185+
url = "https://msedgedriver.microsoft.com/139.0.3405.86/edgedriver_mac64.zip",
186+
sha256 = "b6c8244dfb7b8a223d3ac8fd569533f0a307eadaca2b8cbc884ce7f69294682e",
187187
build_file_content = """
188188
load("@aspect_rules_js//js:defs.bzl", "js_library")
189189
package(default_visibility = ["//visibility:public"])

dotnet/src/webdriver/DriverProcessStartedEventArgs.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
using System;
2121
using System.Diagnostics;
22-
using System.IO;
2322

2423
namespace OpenQA.Selenium;
2524

@@ -41,31 +40,10 @@ public DriverProcessStartedEventArgs(Process driverProcess)
4140
}
4241

4342
this.ProcessId = driverProcess.Id;
44-
if (driverProcess.StartInfo.RedirectStandardOutput && !driverProcess.StartInfo.UseShellExecute)
45-
{
46-
this.StandardOutputStreamReader = driverProcess.StandardOutput;
47-
}
48-
49-
if (driverProcess.StartInfo.RedirectStandardError && !driverProcess.StartInfo.UseShellExecute)
50-
{
51-
this.StandardErrorStreamReader = driverProcess.StandardError;
52-
}
5343
}
5444

5545
/// <summary>
5646
/// Gets the unique ID of the driver executable process.
5747
/// </summary>
5848
public int ProcessId { get; }
59-
60-
/// <summary>
61-
/// Gets a <see cref="StreamReader"/> object that can be used to read the contents
62-
/// printed to <c>stdout</c> by a driver service process.
63-
/// </summary>
64-
public StreamReader? StandardOutputStreamReader { get; }
65-
66-
/// <summary>
67-
/// Gets a <see cref="StreamReader"/> object that can be used to read the contents
68-
/// printed to <c>stderr</c> by a driver service process.
69-
/// </summary>
70-
public StreamReader? StandardErrorStreamReader { get; }
7149
}

dotnet/src/webdriver/DriverService.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Net;
2727
using System.Net.Http;
2828
using System.Threading.Tasks;
29+
using OpenQA.Selenium.Internal.Logging;
2930

3031
namespace OpenQA.Selenium;
3132

@@ -37,6 +38,8 @@ public abstract class DriverService : ICommandServer
3738
private bool isDisposed;
3839
private Process? driverServiceProcess;
3940

41+
private static readonly ILogger _logger = Log.GetLogger(typeof(DriverService));
42+
4043
/// <summary>
4144
/// Initializes a new instance of the <see cref="DriverService"/> class.
4245
/// </summary>
@@ -243,11 +246,22 @@ public void Start()
243246
this.driverServiceProcess.StartInfo.UseShellExecute = false;
244247
this.driverServiceProcess.StartInfo.CreateNoWindow = this.HideCommandPromptWindow;
245248

249+
this.driverServiceProcess.StartInfo.RedirectStandardOutput = true;
250+
this.driverServiceProcess.StartInfo.RedirectStandardError = true;
251+
252+
this.driverServiceProcess.OutputDataReceived += this.OnDriverProcessDataReceived;
253+
this.driverServiceProcess.ErrorDataReceived += this.OnDriverProcessDataReceived;
254+
246255
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo);
247256
this.OnDriverProcessStarting(eventArgs);
248257

258+
// Important: Start the process and immediately begin reading the output and error streams to avoid IO deadlocks.
249259
this.driverServiceProcess.Start();
260+
this.driverServiceProcess.BeginOutputReadLine();
261+
this.driverServiceProcess.BeginErrorReadLine();
262+
250263
bool serviceAvailable = this.WaitForServiceInitialization();
264+
251265
DriverProcessStartedEventArgs processStartedEventArgs = new DriverProcessStartedEventArgs(this.driverServiceProcess);
252266
this.OnDriverProcessStarted(processStartedEventArgs);
253267

@@ -274,6 +288,12 @@ protected virtual void Dispose(bool disposing)
274288
if (disposing)
275289
{
276290
this.Stop();
291+
292+
if (this.driverServiceProcess is not null)
293+
{
294+
this.driverServiceProcess.OutputDataReceived -= this.OnDriverProcessDataReceived;
295+
this.driverServiceProcess.ErrorDataReceived -= this.OnDriverProcessDataReceived;
296+
}
277297
}
278298

279299
this.isDisposed = true;
@@ -308,6 +328,23 @@ protected virtual void OnDriverProcessStarted(DriverProcessStartedEventArgs even
308328
this.DriverProcessStarted?.Invoke(this, eventArgs);
309329
}
310330

331+
/// <summary>
332+
/// Handles the output and error data received from the driver process.
333+
/// </summary>
334+
/// <param name="sender">The sender of the event.</param>
335+
/// <param name="args">The data received event arguments.</param>
336+
/// <param name="isError">A value indicating whether the data received is from the error stream.</param>
337+
protected virtual void OnDriverProcessDataReceived(object sender, DataReceivedEventArgs args)
338+
{
339+
if (string.IsNullOrEmpty(args.Data))
340+
return;
341+
342+
if (_logger.IsEnabled(LogEventLevel.Trace))
343+
{
344+
_logger.Trace(args.Data);
345+
}
346+
}
347+
311348
/// <summary>
312349
/// Stops the DriverService.
313350
/// </summary>

dotnet/src/webdriver/Firefox/FirefoxDriverService.cs

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
using OpenQA.Selenium.Internal;
2121
using System;
22+
using System.Diagnostics;
2223
using System.Globalization;
2324
using System.IO;
2425
using System.Text;
25-
using System.Threading.Tasks;
2626

2727
namespace OpenQA.Selenium.Firefox;
2828

@@ -223,11 +223,11 @@ protected override string CommandLineArguments
223223
}
224224

225225
/// <summary>
226-
/// Handles the event when the driver service process is starting.
226+
/// Called when the driver process is starting. This method sets up log file writing if a log path is specified.
227227
/// </summary>
228228
/// <param name="eventArgs">The event arguments containing information about the driver service process.</param>
229229
/// <remarks>
230-
/// This method initializes a log writer if a log path is specified and redirects output streams to capture logs.
230+
/// This method initializes a log writer if a log path is specified.
231231
/// </remarks>
232232
protected override void OnDriverProcessStarting(DriverProcessStartingEventArgs eventArgs)
233233
{
@@ -239,40 +239,36 @@ protected override void OnDriverProcessStarting(DriverProcessStartingEventArgs e
239239
Directory.CreateDirectory(directory);
240240
}
241241

242-
// Initialize the log writer
243242
logWriter = new StreamWriter(this.LogPath, append: true) { AutoFlush = true };
244-
245-
// Configure process to redirect output
246-
eventArgs.DriverServiceProcessStartInfo.RedirectStandardOutput = true;
247-
eventArgs.DriverServiceProcessStartInfo.RedirectStandardError = true;
248243
}
249244

250245
base.OnDriverProcessStarting(eventArgs);
251246
}
252247

253248
/// <summary>
254-
/// Handles the event when the driver process has started.
249+
/// Handles the output and error data received from the driver process and sends it to the log writer if available.
255250
/// </summary>
256-
/// <param name="eventArgs">The event arguments containing information about the started driver process.</param>
257-
/// <remarks>
258-
/// This method reads the output and error streams asynchronously and writes them to the log file if available.
259-
/// </remarks>
260-
protected override void OnDriverProcessStarted(DriverProcessStartedEventArgs eventArgs)
251+
/// <param name="sender">The sender of the event.</param>
252+
/// <param name="args">The data received event arguments.</param>
253+
protected override void OnDriverProcessDataReceived(object sender, DataReceivedEventArgs args)
261254
{
262-
if (logWriter == null) return;
263-
if (eventArgs.StandardOutputStreamReader != null)
255+
if (string.IsNullOrEmpty(args.Data))
256+
return;
257+
258+
if (!string.IsNullOrEmpty(this.LogPath))
264259
{
265-
_ = Task.Run(() => ReadStreamAsync(eventArgs.StandardOutputStreamReader));
260+
if (logWriter != null)
261+
{
262+
logWriter.WriteLine(args.Data);
263+
}
266264
}
267-
268-
if (eventArgs.StandardErrorStreamReader != null)
265+
else
269266
{
270-
_ = Task.Run(() => ReadStreamAsync(eventArgs.StandardErrorStreamReader));
267+
base.OnDriverProcessDataReceived(sender, args);
271268
}
272-
273-
base.OnDriverProcessStarted(eventArgs);
274269
}
275270

271+
276272
/// <summary>
277273
/// Disposes of the resources used by the <see cref="FirefoxDriverService"/> instance.
278274
/// </summary>
@@ -282,13 +278,13 @@ protected override void OnDriverProcessStarted(DriverProcessStartedEventArgs eve
282278
/// </remarks>
283279
protected override void Dispose(bool disposing)
284280
{
281+
base.Dispose(disposing);
282+
285283
if (logWriter != null && disposing)
286284
{
287285
logWriter.Dispose();
288286
logWriter = null;
289287
}
290-
291-
base.Dispose(disposing);
292288
}
293289

294290
/// <summary>
@@ -372,24 +368,4 @@ private static string FirefoxDriverServiceFileName()
372368

373369
return fileName;
374370
}
375-
376-
private async Task ReadStreamAsync(StreamReader reader)
377-
{
378-
try
379-
{
380-
string? line;
381-
while ((line = await reader.ReadLineAsync()) != null)
382-
{
383-
if (logWriter != null)
384-
{
385-
logWriter.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} {line}");
386-
}
387-
}
388-
}
389-
catch (Exception ex)
390-
{
391-
// Log or handle the exception appropriately
392-
System.Diagnostics.Debug.WriteLine($"Error reading stream: {ex.Message}");
393-
}
394-
}
395371
}

dotnet/test/firefox/FirefoxDriverServiceTest.cs

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,52 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
using System.Collections.Generic;
2022
using NUnit.Framework;
2123
using System.IO;
24+
using System.Linq;
25+
using OpenQA.Selenium.Internal.Logging;
2226

2327
namespace OpenQA.Selenium.Firefox;
2428

2529
[TestFixture]
26-
public class FirefoxDriverServiceTest : DriverTestFixture
30+
public class FirefoxDriverServiceTest
2731
{
32+
private TestLogHandler testLogHandler;
33+
34+
private void ResetGlobalLog()
35+
{
36+
Log.SetLevel(LogEventLevel.Info);
37+
Log.Handlers.Clear().Handlers.Add(new TextWriterHandler(Console.Error));
38+
}
39+
40+
[SetUp]
41+
public void SetUp()
42+
{
43+
ResetGlobalLog();
44+
45+
testLogHandler = new TestLogHandler();
46+
}
47+
48+
[TearDown]
49+
public void TearDown()
50+
{
51+
ResetGlobalLog();
52+
}
53+
2854
[Test]
2955
public void ShouldRedirectGeckoDriverLogsToFile()
3056
{
3157
FirefoxOptions options = new FirefoxOptions();
3258
string logPath = Path.GetTempFileName();
33-
options.LogLevel = FirefoxDriverLogLevel.Trace;
59+
options.LogLevel = FirefoxDriverLogLevel.Info;
3460

3561
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
3662
service.LogPath = logPath;
3763

38-
IWebDriver driver2 = new FirefoxDriver(service, options);
64+
IWebDriver firefoxDriver = new FirefoxDriver(service, options);
65+
firefoxDriver.Quit();
3966

4067
try
4168
{
@@ -45,9 +72,44 @@ public void ShouldRedirectGeckoDriverLogsToFile()
4572
}
4673
finally
4774
{
48-
driver2.Quit();
4975
File.Delete(logPath);
5076
}
5177
}
5278

79+
[Test]
80+
public void ShouldRedirectGeckoDriverLogsToConsole()
81+
{
82+
Log.SetLevel(LogEventLevel.Trace).Handlers.Add(testLogHandler);
83+
FirefoxOptions options = new FirefoxOptions();
84+
options.LogLevel = FirefoxDriverLogLevel.Info;
85+
86+
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
87+
88+
IWebDriver firefoxDriver = new FirefoxDriver(service, options);
89+
90+
try
91+
{
92+
Assert.That(testLogHandler.Events, Has.Count.AtLeast(1));
93+
Assert.That(testLogHandler.Events.Any(e => e.Message.Contains("geckodriver")), Is.True);
94+
}
95+
finally
96+
{
97+
firefoxDriver.Quit();
98+
}
99+
}
100+
}
101+
102+
class TestLogHandler : ILogHandler
103+
{
104+
public ILogHandler Clone()
105+
{
106+
return this;
107+
}
108+
109+
public void Handle(LogEvent logEvent)
110+
{
111+
Events.Add(logEvent);
112+
}
113+
114+
public IList<LogEvent> Events { get; internal set; } = new List<LogEvent>();
53115
}

java/spotbugs-excludes.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@
199199
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_INTERFACE" />
200200
</Match>
201201

202-
<Match>
203-
<Class name="org.openqa.selenium.remote.internal.WebElementToJsonConverter" />
204-
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
205-
</Match>
206-
207202
<Match>
208203
<Class name="org.openqa.selenium.chrome.AddHasCasting" />
209204
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />

0 commit comments

Comments
 (0)