Skip to content

Commit 70bc6c2

Browse files
authored
Merge branch 'trunk' into add-enum-for-page-load-strategies
2 parents a68a3b2 + 6620bce commit 70bc6c2

File tree

11 files changed

+254
-38
lines changed

11 files changed

+254
-38
lines changed

Rakefile

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def java_version
5656
end
5757
end
5858

59+
def dotnet_version
60+
File.foreach('dotnet/selenium-dotnet-version.bzl') do |line|
61+
return line.split('=').last.strip.tr('"', '') if line.include?('SE_VERSION')
62+
end
63+
end
64+
65+
def python_version
66+
File.foreach('py/BUILD.bazel') do |line|
67+
return line.split('=').last.strip.tr('"', '') if line.include?('SE_VERSION')
68+
end
69+
end
70+
5971
# The build system used by webdriver is layered on top of rake, and we call it
6072
# "crazy fun" for no readily apparent reason.
6173

@@ -127,7 +139,7 @@ task all: [
127139
:"selenium-java",
128140
'//java/test/org/openqa/selenium/environment:webserver'
129141
]
130-
task all_zip: [:'prep-release-zip']
142+
task all_zip: [:'java-release-zip', :'dotnet-release-zip']
131143
task tests: [
132144
'//java/test/org/openqa/selenium/htmlunit:htmlunit',
133145
'//java/test/org/openqa/selenium/firefox:test-synthesized',
@@ -324,7 +336,28 @@ task ios_driver: [
324336
'//javascript/webdriver/atoms/fragments:get_location_in_view:ios'
325337
]
326338

327-
task 'prep-release-zip': [
339+
task 'dotnet-release-zip': [
340+
'//dotnet/src/webdriver:webdriver-pack',
341+
'//dotnet/src/webdriver:webdriver-strongnamed-pack',
342+
'//dotnet/src/support:support-pack',
343+
'//dotnet/src/support:support-strongnamed-pack',
344+
] do
345+
[
346+
"build/dist/selenium-dotnet-#{dotnet_version}.zip",
347+
"build/dist/selenium-dotnet-strongnamed-#{dotnet_version}.zip",
348+
].each do |f|
349+
rm_f(f) if File.exists?(f)
350+
end
351+
mkdir_p 'build/dist'
352+
File.delete
353+
354+
cp "bazel-bin/dotnet/release.zip", "build/dist/selenium-dotnet-#{dotnet_version}.zip", preserve: false
355+
chmod 0666, "build/dist/selenium-dotnet-#{dotnet_version}.zip"
356+
cp "bazel-bin/dotnet/strongnamed.zip", "build/dist/selenium-dotnet-strongnamed-#{dotnet_version}.zip", preserve: false
357+
chmod 0666, "build/dist/selenium-dotnet-strongnamed-#{dotnet_version}.zip"
358+
end
359+
360+
task 'java-release-zip': [
328361
'//java/src/org/openqa/selenium:client-zip',
329362
'//java/src/org/openqa/selenium/grid:server-zip',
330363
'//java/src/org/openqa/selenium/grid:executable-grid',
@@ -347,7 +380,7 @@ task 'prep-release-zip': [
347380
chmod 0777, "build/dist/selenium-server-#{java_version}.jar"
348381
end
349382

350-
task 'release-java': %i[prep-release-zip publish-maven]
383+
task 'release-java': %i[java-release-zip publish-maven]
351384

352385
def read_m2_user_pass
353386
# First check env vars, then the settings.xml config inside .m2
@@ -376,13 +409,55 @@ def read_m2_user_pass
376409
return [user, pass]
377410
end
378411

412+
task :prepare_release do
413+
RELEASE_TARGETS = [
414+
'//java/src/org/openqa/selenium:client-zip',
415+
'//java/src/org/openqa/selenium/grid:server-zip',
416+
'//java/src/org/openqa/selenium/grid:executable-grid',
417+
'//dotnet/src/webdriver:webdriver-pack',
418+
'//dotnet/src/webdriver:webdriver-strongnamed-pack',
419+
'//dotnet/src/support:support-pack',
420+
'//dotnet/src/support:support-strongnamed-pack',
421+
'//javascript/node/selenium-webdriver:selenium-webdriver',
422+
'//py:selenium-wheel',
423+
'//py:selenium-sdist',
424+
]
425+
426+
RELEASE_TARGETS.each do |target|
427+
Bazel::execute('build', ['--config', 'release'], target)
428+
end
429+
Bazel::execute('build', ['--stamp'], '//rb:selenium-webdriver')
430+
end
431+
432+
PYPI_ASSETS = [
433+
"bazel-bin/py/selenium-#{python_version}-py3-none-any.whl",
434+
"bazel-bin/py/selenium-#{python_version}.tar.gz"
435+
]
436+
437+
task 'publish-pypi' do
438+
PYPI_ASSETS.each do |asset|
439+
sh "python3 -m twine upload #{asset}"
440+
end
441+
end
442+
379443
task 'publish-maven': JAVA_RELEASE_TARGETS do
380444
creds = read_m2_user_pass
381445
JAVA_RELEASE_TARGETS.each do |p|
382446
Bazel::execute('run', ['--stamp', '--define', 'maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2', '--define', "maven_user=#{creds[0]}", '--define', "maven_password=#{creds[1]}", '--define', 'gpg_sign=true'], p)
383447
end
384448
end
385449

450+
NUGET_RELEASE_ASSETS = [
451+
"./bazel-bin/dotnet/src/webdriver/Selenium.WebDriver.#{dotnet_version}.nupkg",
452+
"./bazel-bin/dotnet/src/webdriver/Selenium.Support.#{dotnet_version}.nupkg"
453+
]
454+
455+
task 'publish-nuget' do
456+
NUGET_RELEASE_ASSETS.each do |asset|
457+
sh "dotnet nuget push #{asset} --api-key #{ENV[:NUGET_API_KEY]} --source https://api.nuget.org/v3/index.json"
458+
end
459+
end
460+
386461
task 'publish-maven-snapshot': JAVA_RELEASE_TARGETS do
387462
creds = read_m2_user_pass
388463
if java_version.end_with?('-SNAPSHOT')

common/mirror/selenium

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717
{
1818
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-java-4.16.0.zip"
1919
},
20+
{
21+
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-java-4.16.1.zip"
22+
},
2023
{
2124
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.0.jar"
2225
},
2326
{
2427
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.0.zip"
28+
},
29+
{
30+
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar"
31+
},
32+
{
33+
"browser_download_url": "https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.zip"
2534
}
2635
]
2736
},

dotnet/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ exports_files([
88
pkg_zip(
99
name = "strongnamed",
1010
srcs = [
11-
"//dotnet/src/support:support-strongnamed",
12-
"//dotnet/src/webdriver:webdriver-strongnamed",
11+
"//dotnet/src/support:support-strongnamed-pack",
12+
"//dotnet/src/webdriver:webdriver-strongnamed-pack",
1313
],
1414
)
1515

1616
pkg_zip(
1717
name = "release",
1818
srcs = [
19-
"//dotnet/src/support",
20-
"//dotnet/src/webdriver",
19+
"//dotnet/src/support:support-pack",
20+
"//dotnet/src/webdriver:webdriver-pack",
2121
],
2222
)

dotnet/src/webdriver/IHasDownloads.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public interface IHasDownloads
2828
/// <summary>
2929
/// Retrieves the downloadable files.
3030
/// </summary>
31-
/// <returns>A list of file names available for download.</returns>
32-
List<string> GetDownloadableFiles();
31+
/// <returns>A read-only list of file names available for download.</returns>
32+
IReadOnlyList<string> GetDownloadableFiles();
3333

3434
/// <summary>
3535
/// Downloads a file with the specified file name and returns a dictionary containing the downloaded file's data.

dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,5 @@ public void Handle(LogEvent logEvent)
3636
{
3737
Console.Error.WriteLine($"{logEvent.Timestamp:HH:mm:ss.fff} {_levels[(int)logEvent.Level]} {logEvent.IssuedBy.Name}: {logEvent.Message}");
3838
}
39-
40-
/// <summary>
41-
/// Creates a new instance of the <see cref="ConsoleLogHandler"/> class.
42-
/// </summary>
43-
/// <returns>A new instance of the <see cref="ConsoleLogHandler"/> class.</returns>
44-
public ILogHandler Clone()
45-
{
46-
return this;
47-
}
4839
}
4940
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace OpenQA.Selenium.Internal.Logging
5+
{
6+
/// <summary>
7+
/// Represents a log handler that writes log events to a file.
8+
/// </summary>
9+
public class FileLogHandler : ILogHandler, IDisposable
10+
{
11+
// performance trick to avoid expensive Enum.ToString() with fixed length
12+
private static readonly string[] _levels = { "TRACE", "DEBUG", " INFO", " WARN", "ERROR" };
13+
14+
private FileStream _fileStream;
15+
private StreamWriter _streamWriter;
16+
17+
private readonly object _lockObj = new object();
18+
private bool _isDisposed;
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="FileLogHandler"/> class with the specified file path.
22+
/// </summary>
23+
/// <param name="path">The path of the log file.</param>
24+
public FileLogHandler(string path)
25+
{
26+
if (string.IsNullOrEmpty(path)) throw new ArgumentException("File log path cannot be null or empty.", nameof(path));
27+
28+
var directory = Path.GetDirectoryName(path);
29+
if (!string.IsNullOrWhiteSpace(directory) && !Directory.Exists(directory))
30+
{
31+
Directory.CreateDirectory(directory);
32+
}
33+
34+
_fileStream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
35+
_fileStream.Seek(0, SeekOrigin.End);
36+
_streamWriter = new StreamWriter(_fileStream, System.Text.Encoding.UTF8)
37+
{
38+
AutoFlush = true
39+
};
40+
}
41+
42+
/// <summary>
43+
/// Handles a log event by writing it to the log file.
44+
/// </summary>
45+
/// <param name="logEvent">The log event to handle.</param>
46+
public void Handle(LogEvent logEvent)
47+
{
48+
lock (_lockObj)
49+
{
50+
_streamWriter.WriteLine($"{logEvent.Timestamp:r} {_levels[(int)logEvent.Level]} {logEvent.IssuedBy.Name}: {logEvent.Message}");
51+
}
52+
}
53+
54+
/// <summary>
55+
/// Disposes the file log handler and releases any resources used.
56+
/// </summary>
57+
public void Dispose()
58+
{
59+
Dispose(true);
60+
GC.SuppressFinalize(this);
61+
}
62+
63+
/// <summary>
64+
/// Finalizes the file log handler instance.
65+
/// </summary>
66+
~FileLogHandler()
67+
{
68+
Dispose(false);
69+
}
70+
71+
/// <summary>
72+
/// Disposes the file log handler and releases any resources used.
73+
/// </summary>
74+
/// <param name="disposing">A flag indicating whether to dispose managed resources.</param>
75+
protected virtual void Dispose(bool disposing)
76+
{
77+
lock (_lockObj)
78+
{
79+
if (!_isDisposed)
80+
{
81+
if (disposing)
82+
{
83+
_streamWriter?.Dispose();
84+
_streamWriter = null;
85+
_fileStream?.Dispose();
86+
_fileStream = null;
87+
}
88+
89+
_isDisposed = true;
90+
}
91+
}
92+
}
93+
}
94+
}

dotnet/src/webdriver/Internal/Logging/ILogHandler.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,5 @@ public interface ILogHandler
2828
/// </summary>
2929
/// <param name="logEvent">The log event to handle.</param>
3030
void Handle(LogEvent logEvent);
31-
32-
/// <summary>
33-
/// Creates a clone of the log handler.
34-
/// </summary>
35-
/// <returns>A clone of the log handler.</returns>
36-
ILogHandler Clone();
3731
}
3832
}

dotnet/src/webdriver/Internal/Logging/LogContext.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,16 @@ public ILogContext CreateContext(LogEventLevel minimumLevel)
6060
loggers = new ConcurrentDictionary<Type, ILogger>(_loggers.Select(l => new KeyValuePair<Type, ILogger>(l.Key, new Logger(l.Value.Issuer, minimumLevel))));
6161
}
6262

63-
IList<ILogHandler> handlers = null;
63+
var context = new LogContext(minimumLevel, this, loggers, null);
6464

6565
if (Handlers != null)
6666
{
67-
handlers = new List<ILogHandler>(Handlers.Select(h => h.Clone()));
68-
}
69-
else
70-
{
71-
handlers = new List<ILogHandler>();
67+
foreach (var handler in Handlers)
68+
{
69+
context.Handlers.Add(handler);
70+
}
7271
}
7372

74-
var context = new LogContext(minimumLevel, this, loggers, Handlers);
75-
7673
Log.CurrentContext = context;
7774

7875
return context;
@@ -137,6 +134,19 @@ public ILogContext SetLevel(Type issuer, LogEventLevel level)
137134

138135
public void Dispose()
139136
{
137+
// Dispose log handlers associated with this context
138+
// if they are hot handled by parent context
139+
if (Handlers != null && _parentLogContext != null && _parentLogContext.Handlers != null)
140+
{
141+
foreach (var logHandler in Handlers)
142+
{
143+
if (!_parentLogContext.Handlers.Contains(logHandler))
144+
{
145+
(logHandler as IDisposable)?.Dispose();
146+
}
147+
}
148+
}
149+
140150
Log.CurrentContext = _parentLogContext;
141151
}
142152
}

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ public DevToolsSession GetDevToolsSession(int protocolVersion)
471471
}
472472

473473
/// <summary>
474-
/// Retrieves the downloadable files as a map of file names and their corresponding URLs.
474+
/// Retrieves the downloadable files.
475475
/// </summary>
476-
/// <returns>A list containing file names as keys and URLs as values.</returns>
477-
public List<string> GetDownloadableFiles()
476+
/// <returns>A read-only list of file names available for download.</returns>
477+
public IReadOnlyList<string> GetDownloadableFiles()
478478
{
479479
var enableDownloads = this.Capabilities.GetCapability(CapabilityType.EnableDownloads);
480480
if (enableDownloads == null || !(bool) enableDownloads) {

dotnet/test/common/DownloadsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void CanListDownloadableFiles()
4141
{
4242
DownloadWithBrowser();
4343

44-
List<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
44+
IReadOnlyList<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
4545
Assert.That(names, Contains.Item("file_1.txt"));
4646
Assert.That(names, Contains.Item("file_2.jpg"));
4747
}
@@ -52,7 +52,7 @@ public void CanDownloadFile()
5252
{
5353
DownloadWithBrowser();
5454

55-
List<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
55+
IReadOnlyList<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
5656
string fileName = names[0];
5757
string targetDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
5858

@@ -72,7 +72,7 @@ public void CanDeleteFiles()
7272

7373
((RemoteWebDriver)driver).DeleteDownloadableFiles();
7474

75-
List<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
75+
IReadOnlyList<string> names = ((RemoteWebDriver) driver).GetDownloadableFiles();
7676
Assert.IsEmpty(names, "The names list should be empty.");
7777
}
7878

0 commit comments

Comments
 (0)