From 241d354b191d41542f2a75bcc8425012e302d87c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Thu, 20 Nov 2025 00:41:19 -0500 Subject: [PATCH 01/13] [dotnet] Add syntax highlighting for JavaScript string methods --- .../support/Events/EventFiringWebDriver.cs | 5 +- .../Events/WebDriverScriptEventArgs.cs | 3 +- .../support/Extensions/WebDriverExtensions.cs | 5 +- .../support/Internal/StringSyntaxAttribute.cs | 89 +++++++++++++++++++ dotnet/src/webdriver/DevTools/JavaScript.cs | 5 +- dotnet/src/webdriver/IJavaScriptEngine.cs | 5 +- dotnet/src/webdriver/IJavascriptExecutor.cs | 5 +- dotnet/src/webdriver/InitializationScript.cs | 2 + .../src/webdriver/Internal/FileUtilities.cs | 7 +- .../Internal/StringSyntaxAttribute.cs | 89 +++++++++++++++++++ dotnet/src/webdriver/JavaScriptEngine.cs | 4 +- dotnet/src/webdriver/PinnedScript.cs | 2 + dotnet/src/webdriver/WebDriver.cs | 6 +- 13 files changed, 206 insertions(+), 21 deletions(-) create mode 100644 dotnet/src/support/Internal/StringSyntaxAttribute.cs create mode 100644 dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index a23c4a04bf9ed..7572a67d261cc 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Threading.Tasks; @@ -442,7 +443,7 @@ public void Dispose() /// variable, as if the function were called via "Function.apply" /// /// - public object? ExecuteScript(string script, params object?[] args) + public object? ExecuteScript([StringSyntax("javascript")] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { @@ -542,7 +543,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript(string script, params object?[] args) + public object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { diff --git a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs index be198ecf62945..4aca8096120b9 100644 --- a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs +++ b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs @@ -18,6 +18,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; namespace OpenQA.Selenium.Support.Events; @@ -32,7 +33,7 @@ public class WebDriverScriptEventArgs : EventArgs /// The WebDriver instance used to execute the script. /// The script executed by the driver. /// If or are . - public WebDriverScriptEventArgs(IWebDriver driver, string script) + public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax("javascript")] string script) { this.Driver = driver ?? throw new ArgumentNullException(nameof(driver)); this.Script = script ?? throw new ArgumentNullException(nameof(script)); diff --git a/dotnet/src/support/Extensions/WebDriverExtensions.cs b/dotnet/src/support/Extensions/WebDriverExtensions.cs index 8ef995719dfda..ebad675484418 100644 --- a/dotnet/src/support/Extensions/WebDriverExtensions.cs +++ b/dotnet/src/support/Extensions/WebDriverExtensions.cs @@ -18,6 +18,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace OpenQA.Selenium.Support.Extensions; @@ -71,7 +72,7 @@ public static Screenshot TakeScreenshot(this IWebDriver driver) /// The arguments to the script. /// Thrown if this instance /// does not implement - public static void ExecuteJavaScript(this IWebDriver driver, string script, params object?[] args) + public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax("javascript")] string script, params object?[] args) { ExecuteJavaScriptInternal(driver, script, args); } @@ -87,7 +88,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, string script, para /// Thrown if this instance /// does not implement , or if the actual return type /// of the JavaScript execution does not match the expected type. - public static T? ExecuteJavaScript(this IWebDriver driver, string script, params object?[] args) + public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax("javascript")] string script, params object?[] args) { var value = ExecuteJavaScriptInternal(driver, script, args); if (value == null) diff --git a/dotnet/src/support/Internal/StringSyntaxAttribute.cs b/dotnet/src/support/Internal/StringSyntaxAttribute.cs new file mode 100644 index 0000000000000..bbb12f6a804b1 --- /dev/null +++ b/dotnet/src/support/Internal/StringSyntaxAttribute.cs @@ -0,0 +1,89 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +#if !NET8_0_OR_GREATER + +namespace System.Diagnostics.CodeAnalysis; + +/// Specifies the syntax used in a string. +[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] +internal sealed class StringSyntaxAttribute : Attribute +{ + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + public StringSyntaxAttribute(string syntax) + { + Syntax = syntax; + Arguments = []; + } + + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + /// Optional arguments associated with the specific syntax employed. + public StringSyntaxAttribute(string syntax, params object?[] arguments) + { + Syntax = syntax; + Arguments = arguments; + } + + /// Gets the identifier of the syntax used. + public string Syntax { get; } + + /// Optional arguments associated with the specific syntax employed. + public object?[] Arguments { get; } + + /// The syntax identifier for strings containing composite formats for string formatting. + public const string CompositeFormat = nameof(CompositeFormat); + + /// The syntax identifier for strings containing date format specifiers. + public const string DateOnlyFormat = nameof(DateOnlyFormat); + + /// The syntax identifier for strings containing date and time format specifiers. + public const string DateTimeFormat = nameof(DateTimeFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string EnumFormat = nameof(EnumFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string GuidFormat = nameof(GuidFormat); + + /// The syntax identifier for strings containing JavaScript Object Notation (JSON). + public const string Json = nameof(Json); + + /// The syntax identifier for strings containing numeric format specifiers. + public const string NumericFormat = nameof(NumericFormat); + + /// The syntax identifier for strings containing regular expressions. + public const string Regex = nameof(Regex); + + /// The syntax identifier for strings containing time format specifiers. + public const string TimeOnlyFormat = nameof(TimeOnlyFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string TimeSpanFormat = nameof(TimeSpanFormat); + + /// The syntax identifier for strings containing URIs. + public const string Uri = nameof(Uri); + + /// The syntax identifier for strings containing XML. + public const string Xml = nameof(Xml); +} + +#endif + diff --git a/dotnet/src/webdriver/DevTools/JavaScript.cs b/dotnet/src/webdriver/DevTools/JavaScript.cs index 5ef23219b5563..47e41df083fc3 100644 --- a/dotnet/src/webdriver/DevTools/JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/JavaScript.cs @@ -18,6 +18,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace OpenQA.Selenium.DevTools; @@ -85,7 +86,7 @@ public abstract class JavaScript /// /// The script to add to be evaluated when a new document is opened. /// A task that represents the asynchronous operation. The task result contains the internal ID of the script. - public abstract Task AddScriptToEvaluateOnNewDocument(string script); + public abstract Task AddScriptToEvaluateOnNewDocument([StringSyntax("javascript")] string script); /// /// Removes a JavaScript snippet from evaluate when a new document is opened. @@ -103,7 +104,7 @@ public abstract class JavaScript /// This method is internal to the operation of pinned scripts in Selenium, and /// is therefore internal by design. /// - internal abstract Task Evaluate(string script); + internal abstract Task Evaluate([StringSyntax("javascript")] string script); /// /// Raises the BindingCalled event. diff --git a/dotnet/src/webdriver/IJavaScriptEngine.cs b/dotnet/src/webdriver/IJavaScriptEngine.cs index 0ae8bf8cafb7f..50850717f9779 100644 --- a/dotnet/src/webdriver/IJavaScriptEngine.cs +++ b/dotnet/src/webdriver/IJavaScriptEngine.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace OpenQA.Selenium; @@ -88,7 +89,7 @@ public interface IJavaScriptEngine : IDisposable /// The JavaScript to be loaded on every page. /// A task containing an object representing the script to be loaded on each page. /// If or are . - Task AddInitializationScript(string scriptName, string script); + Task AddInitializationScript(string scriptName, [StringSyntax("javascript")] string script); /// /// Asynchronously removes JavaScript from being loaded on every document load. @@ -112,7 +113,7 @@ public interface IJavaScriptEngine : IDisposable /// The JavaScript to pin /// A task containing a object to use to execute the script. /// If is . - Task PinScript(string script); + Task PinScript([StringSyntax("javascript")] string script); /// /// Unpins a previously pinned script from the browser. diff --git a/dotnet/src/webdriver/IJavascriptExecutor.cs b/dotnet/src/webdriver/IJavascriptExecutor.cs index 5b1fe570e02b3..0b23b6ac2009b 100644 --- a/dotnet/src/webdriver/IJavascriptExecutor.cs +++ b/dotnet/src/webdriver/IJavascriptExecutor.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace OpenQA.Selenium; @@ -62,7 +63,7 @@ public interface IJavaScriptExecutor /// variable, as if the function were called via "Function.apply" /// /// - object? ExecuteScript(string script, params object?[] args); + object? ExecuteScript([StringSyntax("javascript")] string script, params object?[] args); /// /// Executes JavaScript in the context of the currently selected frame or window. @@ -108,5 +109,5 @@ public interface IJavaScriptExecutor /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - object? ExecuteAsyncScript(string script, params object?[] args); + object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[] args); } diff --git a/dotnet/src/webdriver/InitializationScript.cs b/dotnet/src/webdriver/InitializationScript.cs index 189cf02b88888..7dd1defcd1ce3 100644 --- a/dotnet/src/webdriver/InitializationScript.cs +++ b/dotnet/src/webdriver/InitializationScript.cs @@ -18,6 +18,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace OpenQA.Selenium; @@ -47,6 +48,7 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS /// /// Gets the JavaScript source of the initialization script. /// + [StringSyntax("javascript")] public string ScriptSource { get; } /// diff --git a/dotnet/src/webdriver/Internal/FileUtilities.cs b/dotnet/src/webdriver/Internal/FileUtilities.cs index 1603cdbde8ea5..e74dcabc0a93b 100644 --- a/dotnet/src/webdriver/Internal/FileUtilities.cs +++ b/dotnet/src/webdriver/Internal/FileUtilities.cs @@ -19,6 +19,7 @@ using OpenQA.Selenium.Internal.Logging; using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Reflection; @@ -209,11 +210,7 @@ public static string GetCurrentDirectory() /// The pattern to use in creating the directory name, following standard /// .NET string replacement tokens. /// The full path to the random directory name in the temporary directory. - public static string GenerateRandomTempDirectoryName( -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.CompositeFormat)] -#endif - string directoryPattern) + public static string GenerateRandomTempDirectoryName([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string directoryPattern) { string directoryName = string.Format(CultureInfo.InvariantCulture, directoryPattern, Guid.NewGuid().ToString("N")); return Path.Combine(Path.GetTempPath(), directoryName); diff --git a/dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs b/dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs new file mode 100644 index 0000000000000..bbb12f6a804b1 --- /dev/null +++ b/dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs @@ -0,0 +1,89 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +#if !NET8_0_OR_GREATER + +namespace System.Diagnostics.CodeAnalysis; + +/// Specifies the syntax used in a string. +[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] +internal sealed class StringSyntaxAttribute : Attribute +{ + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + public StringSyntaxAttribute(string syntax) + { + Syntax = syntax; + Arguments = []; + } + + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + /// Optional arguments associated with the specific syntax employed. + public StringSyntaxAttribute(string syntax, params object?[] arguments) + { + Syntax = syntax; + Arguments = arguments; + } + + /// Gets the identifier of the syntax used. + public string Syntax { get; } + + /// Optional arguments associated with the specific syntax employed. + public object?[] Arguments { get; } + + /// The syntax identifier for strings containing composite formats for string formatting. + public const string CompositeFormat = nameof(CompositeFormat); + + /// The syntax identifier for strings containing date format specifiers. + public const string DateOnlyFormat = nameof(DateOnlyFormat); + + /// The syntax identifier for strings containing date and time format specifiers. + public const string DateTimeFormat = nameof(DateTimeFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string EnumFormat = nameof(EnumFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string GuidFormat = nameof(GuidFormat); + + /// The syntax identifier for strings containing JavaScript Object Notation (JSON). + public const string Json = nameof(Json); + + /// The syntax identifier for strings containing numeric format specifiers. + public const string NumericFormat = nameof(NumericFormat); + + /// The syntax identifier for strings containing regular expressions. + public const string Regex = nameof(Regex); + + /// The syntax identifier for strings containing time format specifiers. + public const string TimeOnlyFormat = nameof(TimeOnlyFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string TimeSpanFormat = nameof(TimeSpanFormat); + + /// The syntax identifier for strings containing URIs. + public const string Uri = nameof(Uri); + + /// The syntax identifier for strings containing XML. + public const string Xml = nameof(Xml); +} + +#endif + diff --git a/dotnet/src/webdriver/JavaScriptEngine.cs b/dotnet/src/webdriver/JavaScriptEngine.cs index d44f786a06943..65fab281d7296 100644 --- a/dotnet/src/webdriver/JavaScriptEngine.cs +++ b/dotnet/src/webdriver/JavaScriptEngine.cs @@ -164,7 +164,7 @@ public async Task DisableDomMutationMonitoring() /// The JavaScript to be loaded on every page. /// A task containing an object representing the script to be loaded on each page. /// If or are . - public async Task AddInitializationScript(string scriptName, string script) + public async Task AddInitializationScript(string scriptName, [StringSyntax("javascript")] string script) { if (scriptName is null) { @@ -233,7 +233,7 @@ public async Task ClearInitializationScripts() /// The JavaScript to pin /// A task containing a object to use to execute the script. /// If is . - public async Task PinScript(string script) + public async Task PinScript([StringSyntax("javascript")] string script) { if (script == null) { diff --git a/dotnet/src/webdriver/PinnedScript.cs b/dotnet/src/webdriver/PinnedScript.cs index 158f7683c9fdd..1cb65a5e52c46 100644 --- a/dotnet/src/webdriver/PinnedScript.cs +++ b/dotnet/src/webdriver/PinnedScript.cs @@ -17,6 +17,7 @@ // under the License. // +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace OpenQA.Selenium; @@ -53,6 +54,7 @@ internal PinnedScript(string script, string stringHandle, string scriptId) /// /// Gets the source representing the body of the function in the pinned script. /// + [StringSyntax("javascript")] public string Source { get; } internal static string MakeCreationScript(string scriptHandle, string scriptSource) diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 77f82461053d7..c13c8f364b267 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -234,7 +234,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript(string script, params object?[]? args) + public object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[]? args) { return this.ExecuteScriptCommand(script, DriverCommand.ExecuteAsyncScript, args); } @@ -245,7 +245,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteScript(string script, params object?[]? args) + public object? ExecuteScript([StringSyntax("javascript")] string script, params object?[]? args) { return this.ExecuteScriptCommand(script, DriverCommand.ExecuteScript, args); } @@ -834,7 +834,7 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command /// The name of the command to execute. /// The arguments to the script. /// The value returned by the script. - protected object? ExecuteScriptCommand(string script, string commandName, params object?[]? args) + protected object? ExecuteScriptCommand([StringSyntax("javascript")] string script, string commandName, params object?[]? args) { object?[] convertedArgs = ConvertArgumentsToJavaScriptObjects(args); From 874c1614f6ad33e4d0fc3e1d23f700a5d2bb3d8b Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 21:13:17 -0500 Subject: [PATCH 02/13] Use const for JavaScript --- dotnet/src/webdriver/DevTools/JavaScript.cs | 5 +++-- dotnet/src/webdriver/IJavaScriptEngine.cs | 5 +++-- dotnet/src/webdriver/IJavascriptExecutor.cs | 5 +++-- dotnet/src/webdriver/InitializationScript.cs | 3 ++- dotnet/src/webdriver/Internal/StringSyntaxConstants.cs | 10 ++++++++++ dotnet/src/webdriver/JavaScriptEngine.cs | 4 ++-- dotnet/src/webdriver/PinnedScript.cs | 3 ++- dotnet/src/webdriver/WebDriver.cs | 6 +++--- 8 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 dotnet/src/webdriver/Internal/StringSyntaxConstants.cs diff --git a/dotnet/src/webdriver/DevTools/JavaScript.cs b/dotnet/src/webdriver/DevTools/JavaScript.cs index 47e41df083fc3..69f488397754d 100644 --- a/dotnet/src/webdriver/DevTools/JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/JavaScript.cs @@ -20,6 +20,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium.DevTools; @@ -86,7 +87,7 @@ public abstract class JavaScript /// /// The script to add to be evaluated when a new document is opened. /// A task that represents the asynchronous operation. The task result contains the internal ID of the script. - public abstract Task AddScriptToEvaluateOnNewDocument([StringSyntax("javascript")] string script); + public abstract Task AddScriptToEvaluateOnNewDocument([StringSyntax(StringSyntaxConstants.JavaScript)] string script); /// /// Removes a JavaScript snippet from evaluate when a new document is opened. @@ -104,7 +105,7 @@ public abstract class JavaScript /// This method is internal to the operation of pinned scripts in Selenium, and /// is therefore internal by design. /// - internal abstract Task Evaluate([StringSyntax("javascript")] string script); + internal abstract Task Evaluate([StringSyntax(StringSyntaxConstants.JavaScript)] string script); /// /// Raises the BindingCalled event. diff --git a/dotnet/src/webdriver/IJavaScriptEngine.cs b/dotnet/src/webdriver/IJavaScriptEngine.cs index 50850717f9779..2dd71d6bc1fd8 100644 --- a/dotnet/src/webdriver/IJavaScriptEngine.cs +++ b/dotnet/src/webdriver/IJavaScriptEngine.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium; @@ -89,7 +90,7 @@ public interface IJavaScriptEngine : IDisposable /// The JavaScript to be loaded on every page. /// A task containing an object representing the script to be loaded on each page. /// If or are . - Task AddInitializationScript(string scriptName, [StringSyntax("javascript")] string script); + Task AddInitializationScript(string scriptName, [StringSyntax(StringSyntaxConstants.JavaScript)] string script); /// /// Asynchronously removes JavaScript from being loaded on every document load. @@ -113,7 +114,7 @@ public interface IJavaScriptEngine : IDisposable /// The JavaScript to pin /// A task containing a object to use to execute the script. /// If is . - Task PinScript([StringSyntax("javascript")] string script); + Task PinScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script); /// /// Unpins a previously pinned script from the browser. diff --git a/dotnet/src/webdriver/IJavascriptExecutor.cs b/dotnet/src/webdriver/IJavascriptExecutor.cs index 0b23b6ac2009b..9f4de14c29c32 100644 --- a/dotnet/src/webdriver/IJavascriptExecutor.cs +++ b/dotnet/src/webdriver/IJavascriptExecutor.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium; @@ -63,7 +64,7 @@ public interface IJavaScriptExecutor /// variable, as if the function were called via "Function.apply" /// /// - object? ExecuteScript([StringSyntax("javascript")] string script, params object?[] args); + object? ExecuteScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args); /// /// Executes JavaScript in the context of the currently selected frame or window. @@ -109,5 +110,5 @@ public interface IJavaScriptExecutor /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[] args); + object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args); } diff --git a/dotnet/src/webdriver/InitializationScript.cs b/dotnet/src/webdriver/InitializationScript.cs index 7dd1defcd1ce3..6cf16079c68ac 100644 --- a/dotnet/src/webdriver/InitializationScript.cs +++ b/dotnet/src/webdriver/InitializationScript.cs @@ -20,6 +20,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium; @@ -48,7 +49,7 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS /// /// Gets the JavaScript source of the initialization script. /// - [StringSyntax("javascript")] + [StringSyntax(StringSyntaxConstants.JavaScript)] public string ScriptSource { get; } /// diff --git a/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs b/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs new file mode 100644 index 0000000000000..b394cdff1c590 --- /dev/null +++ b/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenQA.Selenium.Internal; + +internal static class StringSyntaxConstants +{ + public const string JavaScript = "javascript"; +} diff --git a/dotnet/src/webdriver/JavaScriptEngine.cs b/dotnet/src/webdriver/JavaScriptEngine.cs index 65fab281d7296..86f20c64c6f2c 100644 --- a/dotnet/src/webdriver/JavaScriptEngine.cs +++ b/dotnet/src/webdriver/JavaScriptEngine.cs @@ -164,7 +164,7 @@ public async Task DisableDomMutationMonitoring() /// The JavaScript to be loaded on every page. /// A task containing an object representing the script to be loaded on each page. /// If or are . - public async Task AddInitializationScript(string scriptName, [StringSyntax("javascript")] string script) + public async Task AddInitializationScript(string scriptName, [StringSyntax(StringSyntaxConstants.JavaScript)] string script) { if (scriptName is null) { @@ -233,7 +233,7 @@ public async Task ClearInitializationScripts() /// The JavaScript to pin /// A task containing a object to use to execute the script. /// If is . - public async Task PinScript([StringSyntax("javascript")] string script) + public async Task PinScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script) { if (script == null) { diff --git a/dotnet/src/webdriver/PinnedScript.cs b/dotnet/src/webdriver/PinnedScript.cs index 1cb65a5e52c46..a51fea3d0cc60 100644 --- a/dotnet/src/webdriver/PinnedScript.cs +++ b/dotnet/src/webdriver/PinnedScript.cs @@ -19,6 +19,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium; @@ -54,7 +55,7 @@ internal PinnedScript(string script, string stringHandle, string scriptId) /// /// Gets the source representing the body of the function in the pinned script. /// - [StringSyntax("javascript")] + [StringSyntax(StringSyntaxConstants.JavaScript)] public string Source { get; } internal static string MakeCreationScript(string scriptHandle, string scriptSource) diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index c13c8f364b267..45181ed88a2c0 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -234,7 +234,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[]? args) + public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[]? args) { return this.ExecuteScriptCommand(script, DriverCommand.ExecuteAsyncScript, args); } @@ -245,7 +245,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteScript([StringSyntax("javascript")] string script, params object?[]? args) + public object? ExecuteScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[]? args) { return this.ExecuteScriptCommand(script, DriverCommand.ExecuteScript, args); } @@ -834,7 +834,7 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command /// The name of the command to execute. /// The arguments to the script. /// The value returned by the script. - protected object? ExecuteScriptCommand([StringSyntax("javascript")] string script, string commandName, params object?[]? args) + protected object? ExecuteScriptCommand([StringSyntax(StringSyntaxConstants.JavaScript)] string script, string commandName, params object?[]? args) { object?[] convertedArgs = ConvertArgumentsToJavaScriptObjects(args); From 149791f73b8a93e18781e8152a7a330ec5a2019c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 21:36:59 -0500 Subject: [PATCH 03/13] Avoid ifdef in the support package --- dotnet/src/support/Internal/StringSyntaxAttribute.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dotnet/src/support/Internal/StringSyntaxAttribute.cs b/dotnet/src/support/Internal/StringSyntaxAttribute.cs index bbb12f6a804b1..86a5233e22aed 100644 --- a/dotnet/src/support/Internal/StringSyntaxAttribute.cs +++ b/dotnet/src/support/Internal/StringSyntaxAttribute.cs @@ -17,8 +17,6 @@ // under the License. // -#if !NET8_0_OR_GREATER - namespace System.Diagnostics.CodeAnalysis; /// Specifies the syntax used in a string. @@ -84,6 +82,3 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); } - -#endif - From 37588baed06c0adb37c6ef11aed5b9b2b2d3ef02 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 21:41:44 -0500 Subject: [PATCH 04/13] Add const to support package too --- .../support/Events/EventFiringWebDriver.cs | 5 ++-- .../Events/WebDriverScriptEventArgs.cs | 3 ++- .../support/Extensions/WebDriverExtensions.cs | 5 ++-- .../support/Internal/StringSyntaxConstants.cs | 25 +++++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 dotnet/src/support/Internal/StringSyntaxConstants.cs diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index 7572a67d261cc..974843dbce1e4 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -23,6 +23,7 @@ using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Threading.Tasks; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium.Support.Events; @@ -443,7 +444,7 @@ public void Dispose() /// variable, as if the function were called via "Function.apply" /// /// - public object? ExecuteScript([StringSyntax("javascript")] string script, params object?[] args) + public object? ExecuteScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { @@ -543,7 +544,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript([StringSyntax("javascript")] string script, params object?[] args) + public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { diff --git a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs index 4aca8096120b9..ab9bfd254eccb 100644 --- a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs +++ b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs @@ -19,6 +19,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium.Support.Events; @@ -33,7 +34,7 @@ public class WebDriverScriptEventArgs : EventArgs /// The WebDriver instance used to execute the script. /// The script executed by the driver. /// If or are . - public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax("javascript")] string script) + public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script) { this.Driver = driver ?? throw new ArgumentNullException(nameof(driver)); this.Script = script ?? throw new ArgumentNullException(nameof(script)); diff --git a/dotnet/src/support/Extensions/WebDriverExtensions.cs b/dotnet/src/support/Extensions/WebDriverExtensions.cs index ebad675484418..64b81bdc62caa 100644 --- a/dotnet/src/support/Extensions/WebDriverExtensions.cs +++ b/dotnet/src/support/Extensions/WebDriverExtensions.cs @@ -20,6 +20,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium.Support.Extensions; @@ -72,7 +73,7 @@ public static Screenshot TakeScreenshot(this IWebDriver driver) /// The arguments to the script. /// Thrown if this instance /// does not implement - public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax("javascript")] string script, params object?[] args) + public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { ExecuteJavaScriptInternal(driver, script, args); } @@ -88,7 +89,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax("java /// Thrown if this instance /// does not implement , or if the actual return type /// of the JavaScript execution does not match the expected type. - public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax("javascript")] string script, params object?[] args) + public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { var value = ExecuteJavaScriptInternal(driver, script, args); if (value == null) diff --git a/dotnet/src/support/Internal/StringSyntaxConstants.cs b/dotnet/src/support/Internal/StringSyntaxConstants.cs new file mode 100644 index 0000000000000..55547e66244bc --- /dev/null +++ b/dotnet/src/support/Internal/StringSyntaxConstants.cs @@ -0,0 +1,25 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +namespace OpenQA.Selenium.Internal; + +internal static class StringSyntaxConstants +{ + public const string JavaScript = "javascript"; +} From 0cd6f3539c6d343fc88805ac5c78c808a2f1dc31 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 23:33:02 -0500 Subject: [PATCH 05/13] Work around internal issue --- dotnet/src/support/BUILD.bazel | 2 + .../support/Events/EventFiringWebDriver.cs | 4 +- .../Events/WebDriverScriptEventArgs.cs | 2 +- .../support/Extensions/WebDriverExtensions.cs | 4 +- .../support/Internal/StringSyntaxAttribute.cs | 84 ------------------- ...nts.cs => StringSyntaxConstantsSupport.cs} | 4 +- .../support/Selenium.WebDriver.Support.csproj | 5 ++ 7 files changed, 14 insertions(+), 91 deletions(-) delete mode 100644 dotnet/src/support/Internal/StringSyntaxAttribute.cs rename dotnet/src/support/Internal/{StringSyntaxConstants.cs => StringSyntaxConstantsSupport.cs} (87%) diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index 930e842870ee8..f01c16be3ff83 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -32,6 +32,7 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", + "../webdriver/Internal/StringSyntaxAttribute.cs", ]) + [":assembly-info"], out = "WebDriver.Support", langversion = "12.0", @@ -71,6 +72,7 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", + "../webdriver/Internal/StringSyntaxAttribute.cs", ]) + [":assembly-info"], out = "WebDriver.Support.StrongNamed", keyfile = "//dotnet:Selenium.snk", diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index 974843dbce1e4..6251be3d6affe 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -444,7 +444,7 @@ public void Dispose() /// variable, as if the function were called via "Function.apply" /// /// - public object? ExecuteScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) + public object? ExecuteScript([StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { @@ -544,7 +544,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) + public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { diff --git a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs index ab9bfd254eccb..d8d1ecb177fe0 100644 --- a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs +++ b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs @@ -34,7 +34,7 @@ public class WebDriverScriptEventArgs : EventArgs /// The WebDriver instance used to execute the script. /// The script executed by the driver. /// If or are . - public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script) + public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script) { this.Driver = driver ?? throw new ArgumentNullException(nameof(driver)); this.Script = script ?? throw new ArgumentNullException(nameof(script)); diff --git a/dotnet/src/support/Extensions/WebDriverExtensions.cs b/dotnet/src/support/Extensions/WebDriverExtensions.cs index 64b81bdc62caa..33800318d3c39 100644 --- a/dotnet/src/support/Extensions/WebDriverExtensions.cs +++ b/dotnet/src/support/Extensions/WebDriverExtensions.cs @@ -73,7 +73,7 @@ public static Screenshot TakeScreenshot(this IWebDriver driver) /// The arguments to the script. /// Thrown if this instance /// does not implement - public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) + public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) { ExecuteJavaScriptInternal(driver, script, args); } @@ -89,7 +89,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(Strin /// Thrown if this instance /// does not implement , or if the actual return type /// of the JavaScript execution does not match the expected type. - public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) + public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) { var value = ExecuteJavaScriptInternal(driver, script, args); if (value == null) diff --git a/dotnet/src/support/Internal/StringSyntaxAttribute.cs b/dotnet/src/support/Internal/StringSyntaxAttribute.cs deleted file mode 100644 index 86a5233e22aed..0000000000000 --- a/dotnet/src/support/Internal/StringSyntaxAttribute.cs +++ /dev/null @@ -1,84 +0,0 @@ -// -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -namespace System.Diagnostics.CodeAnalysis; - -/// Specifies the syntax used in a string. -[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] -internal sealed class StringSyntaxAttribute : Attribute -{ - /// Initializes the with the identifier of the syntax used. - /// The syntax identifier. - public StringSyntaxAttribute(string syntax) - { - Syntax = syntax; - Arguments = []; - } - - /// Initializes the with the identifier of the syntax used. - /// The syntax identifier. - /// Optional arguments associated with the specific syntax employed. - public StringSyntaxAttribute(string syntax, params object?[] arguments) - { - Syntax = syntax; - Arguments = arguments; - } - - /// Gets the identifier of the syntax used. - public string Syntax { get; } - - /// Optional arguments associated with the specific syntax employed. - public object?[] Arguments { get; } - - /// The syntax identifier for strings containing composite formats for string formatting. - public const string CompositeFormat = nameof(CompositeFormat); - - /// The syntax identifier for strings containing date format specifiers. - public const string DateOnlyFormat = nameof(DateOnlyFormat); - - /// The syntax identifier for strings containing date and time format specifiers. - public const string DateTimeFormat = nameof(DateTimeFormat); - - /// The syntax identifier for strings containing format specifiers. - public const string EnumFormat = nameof(EnumFormat); - - /// The syntax identifier for strings containing format specifiers. - public const string GuidFormat = nameof(GuidFormat); - - /// The syntax identifier for strings containing JavaScript Object Notation (JSON). - public const string Json = nameof(Json); - - /// The syntax identifier for strings containing numeric format specifiers. - public const string NumericFormat = nameof(NumericFormat); - - /// The syntax identifier for strings containing regular expressions. - public const string Regex = nameof(Regex); - - /// The syntax identifier for strings containing time format specifiers. - public const string TimeOnlyFormat = nameof(TimeOnlyFormat); - - /// The syntax identifier for strings containing format specifiers. - public const string TimeSpanFormat = nameof(TimeSpanFormat); - - /// The syntax identifier for strings containing URIs. - public const string Uri = nameof(Uri); - - /// The syntax identifier for strings containing XML. - public const string Xml = nameof(Xml); -} diff --git a/dotnet/src/support/Internal/StringSyntaxConstants.cs b/dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs similarity index 87% rename from dotnet/src/support/Internal/StringSyntaxConstants.cs rename to dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs index 55547e66244bc..cf08624f836de 100644 --- a/dotnet/src/support/Internal/StringSyntaxConstants.cs +++ b/dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,7 +19,7 @@ namespace OpenQA.Selenium.Internal; -internal static class StringSyntaxConstants +internal static class StringSyntaxConstantsSupport { public const string JavaScript = "javascript"; } diff --git a/dotnet/src/support/Selenium.WebDriver.Support.csproj b/dotnet/src/support/Selenium.WebDriver.Support.csproj index 1ddf670d553c8..75475a2196014 100644 --- a/dotnet/src/support/Selenium.WebDriver.Support.csproj +++ b/dotnet/src/support/Selenium.WebDriver.Support.csproj @@ -40,4 +40,9 @@ + + + + + From 0436c3b2e028407f2da8559d87ff070699ffff4a Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 23:44:23 -0500 Subject: [PATCH 06/13] Fix bazel build --- dotnet/BUILD.bazel | 6 ++++++ dotnet/src/support/BUILD.bazel | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index 44ded9c69201b..02c8260f79ce7 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -26,3 +26,9 @@ pkg_zip( "release-artifact", ], ) + +filegroup( + name = "source_files_support_needs_from_core", + srcs = ["webdriver/Internal/StringSyntaxAttribute.cs"], + visibility = ["//tgt:__pkg__"], +) \ No newline at end of file diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index f01c16be3ff83..6c39a5e0c1004 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -32,8 +32,7 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", - "../webdriver/Internal/StringSyntaxAttribute.cs", - ]) + [":assembly-info"], + ]) + [":assembly-info", "//dotnet:source_files_support_needs_from_core"], out = "WebDriver.Support", langversion = "12.0", nullable = "enable", @@ -72,8 +71,7 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", - "../webdriver/Internal/StringSyntaxAttribute.cs", - ]) + [":assembly-info"], + ]) + [":assembly-info", "//dotnet:source_files_support_needs_from_core"], out = "WebDriver.Support.StrongNamed", keyfile = "//dotnet:Selenium.snk", langversion = "12.0", From 21df0292eb2a4358f616d4a59f08ec1af5e4676c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 23:48:39 -0500 Subject: [PATCH 07/13] fix whitespace --- dotnet/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index 02c8260f79ce7..f334da277d8b9 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -31,4 +31,4 @@ filegroup( name = "source_files_support_needs_from_core", srcs = ["webdriver/Internal/StringSyntaxAttribute.cs"], visibility = ["//tgt:__pkg__"], -) \ No newline at end of file +) From 0310a8382666e7f6fbae5df2c1a7b797ca6b727a Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Nov 2025 23:59:33 -0500 Subject: [PATCH 08/13] Fix path to internal file --- dotnet/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index f334da277d8b9..9238a1b886b4c 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -29,6 +29,6 @@ pkg_zip( filegroup( name = "source_files_support_needs_from_core", - srcs = ["webdriver/Internal/StringSyntaxAttribute.cs"], + srcs = ["//dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs"], visibility = ["//tgt:__pkg__"], ) From e2f77e7333c15353b195b465004223d8f4a5633c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 22 Nov 2025 00:12:00 -0500 Subject: [PATCH 09/13] Use glob to indicate direct file --- dotnet/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index 9238a1b886b4c..a9e87e9b97b52 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -29,6 +29,6 @@ pkg_zip( filegroup( name = "source_files_support_needs_from_core", - srcs = ["//dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs"], + srcs = glob(["dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs"]), visibility = ["//tgt:__pkg__"], ) From 4843fbb307dc97ecec4de9eb324523cb0240b18e Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 22 Nov 2025 00:31:53 -0500 Subject: [PATCH 10/13] Fix file visibility --- dotnet/BUILD.bazel | 2 +- dotnet/src/webdriver/BUILD.bazel | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index a9e87e9b97b52..e85255a839e83 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -29,6 +29,6 @@ pkg_zip( filegroup( name = "source_files_support_needs_from_core", - srcs = glob(["dotnet/src/webdriver/Internal/StringSyntaxAttribute.cs"]), + srcs = ["//dotnet/src/webdriver:Internal/StringSyntaxAttribute.cs"], visibility = ["//tgt:__pkg__"], ) diff --git a/dotnet/src/webdriver/BUILD.bazel b/dotnet/src/webdriver/BUILD.bazel index 0d57751f521e1..c175d78a2d0f0 100644 --- a/dotnet/src/webdriver/BUILD.bazel +++ b/dotnet/src/webdriver/BUILD.bazel @@ -12,6 +12,7 @@ load( exports_files([ "WebDriver.csproj", + "Internal/StringSyntaxAttribute.cs" ]) generated_assembly_info( From 7b9d15db0a1376b40ba5a77c4ae2ea60bd9d93db Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 22 Nov 2025 00:49:05 -0500 Subject: [PATCH 11/13] Fix reference to StringSyntaxConstants as well --- dotnet/BUILD.bazel | 7 ++++-- .../support/Events/EventFiringWebDriver.cs | 4 +-- .../Events/WebDriverScriptEventArgs.cs | 2 +- .../support/Extensions/WebDriverExtensions.cs | 4 +-- .../Internal/StringSyntaxConstantsSupport.cs | 25 ------------------- .../support/Selenium.WebDriver.Support.csproj | 3 ++- dotnet/src/webdriver/BUILD.bazel | 3 ++- 7 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index e85255a839e83..da92a9358747b 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -29,6 +29,9 @@ pkg_zip( filegroup( name = "source_files_support_needs_from_core", - srcs = ["//dotnet/src/webdriver:Internal/StringSyntaxAttribute.cs"], - visibility = ["//tgt:__pkg__"], + srcs = [ + "//dotnet/src/webdriver:Internal/StringSyntaxAttribute.cs", + "//dotnet/src/webdriver:Internal/StringSyntaxConstants.cs", + ], + visibility = ["__subpackages__"], ) diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index 6251be3d6affe..974843dbce1e4 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -444,7 +444,7 @@ public void Dispose() /// variable, as if the function were called via "Function.apply" /// /// - public object? ExecuteScript([StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) + public object? ExecuteScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { @@ -544,7 +544,7 @@ public void Dispose() /// The JavaScript code to execute. /// The arguments to the script. /// The value returned by the script. - public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) + public object? ExecuteAsyncScript([StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { if (this.WrappedDriver is not IJavaScriptExecutor javascriptDriver) { diff --git a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs index d8d1ecb177fe0..ab9bfd254eccb 100644 --- a/dotnet/src/support/Events/WebDriverScriptEventArgs.cs +++ b/dotnet/src/support/Events/WebDriverScriptEventArgs.cs @@ -34,7 +34,7 @@ public class WebDriverScriptEventArgs : EventArgs /// The WebDriver instance used to execute the script. /// The script executed by the driver. /// If or are . - public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script) + public WebDriverScriptEventArgs(IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script) { this.Driver = driver ?? throw new ArgumentNullException(nameof(driver)); this.Script = script ?? throw new ArgumentNullException(nameof(script)); diff --git a/dotnet/src/support/Extensions/WebDriverExtensions.cs b/dotnet/src/support/Extensions/WebDriverExtensions.cs index 33800318d3c39..64b81bdc62caa 100644 --- a/dotnet/src/support/Extensions/WebDriverExtensions.cs +++ b/dotnet/src/support/Extensions/WebDriverExtensions.cs @@ -73,7 +73,7 @@ public static Screenshot TakeScreenshot(this IWebDriver driver) /// The arguments to the script. /// Thrown if this instance /// does not implement - public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) + public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { ExecuteJavaScriptInternal(driver, script, args); } @@ -89,7 +89,7 @@ public static void ExecuteJavaScript(this IWebDriver driver, [StringSyntax(Strin /// Thrown if this instance /// does not implement , or if the actual return type /// of the JavaScript execution does not match the expected type. - public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstantsSupport.JavaScript)] string script, params object?[] args) + public static T? ExecuteJavaScript(this IWebDriver driver, [StringSyntax(StringSyntaxConstants.JavaScript)] string script, params object?[] args) { var value = ExecuteJavaScriptInternal(driver, script, args); if (value == null) diff --git a/dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs b/dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs deleted file mode 100644 index cf08624f836de..0000000000000 --- a/dotnet/src/support/Internal/StringSyntaxConstantsSupport.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -namespace OpenQA.Selenium.Internal; - -internal static class StringSyntaxConstantsSupport -{ - public const string JavaScript = "javascript"; -} diff --git a/dotnet/src/support/Selenium.WebDriver.Support.csproj b/dotnet/src/support/Selenium.WebDriver.Support.csproj index 75475a2196014..2d50e149f95e9 100644 --- a/dotnet/src/support/Selenium.WebDriver.Support.csproj +++ b/dotnet/src/support/Selenium.WebDriver.Support.csproj @@ -41,8 +41,9 @@ - + + diff --git a/dotnet/src/webdriver/BUILD.bazel b/dotnet/src/webdriver/BUILD.bazel index c175d78a2d0f0..2d6a8735d4e77 100644 --- a/dotnet/src/webdriver/BUILD.bazel +++ b/dotnet/src/webdriver/BUILD.bazel @@ -12,7 +12,8 @@ load( exports_files([ "WebDriver.csproj", - "Internal/StringSyntaxAttribute.cs" + "Internal/StringSyntaxAttribute.cs", + "Internal/StringSyntaxConstants.cs", ]) generated_assembly_info( From 03375350d8ecbb5520c40a9d406c571a76a5a708 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 22 Nov 2025 01:04:55 -0500 Subject: [PATCH 12/13] Fix build format --- dotnet/src/support/BUILD.bazel | 10 +++++++-- .../support/Selenium.WebDriver.Support.csproj | 2 +- .../Internal/StringSyntaxConstants.cs | 21 ++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index 6c39a5e0c1004..e0eded3bc2e15 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -32,7 +32,10 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", - ]) + [":assembly-info", "//dotnet:source_files_support_needs_from_core"], + ]) + [ + ":assembly-info", + "//dotnet:source_files_support_needs_from_core" + ], out = "WebDriver.Support", langversion = "12.0", nullable = "enable", @@ -71,7 +74,10 @@ csharp_library( "Events/*.cs", "Extensions/*.cs", "UI/*.cs", - ]) + [":assembly-info", "//dotnet:source_files_support_needs_from_core"], + ]) + [ + ":assembly-info", + "//dotnet:source_files_support_needs_from_core" + ], out = "WebDriver.Support.StrongNamed", keyfile = "//dotnet:Selenium.snk", langversion = "12.0", diff --git a/dotnet/src/support/Selenium.WebDriver.Support.csproj b/dotnet/src/support/Selenium.WebDriver.Support.csproj index 2d50e149f95e9..9c0e10cd7a79e 100644 --- a/dotnet/src/support/Selenium.WebDriver.Support.csproj +++ b/dotnet/src/support/Selenium.WebDriver.Support.csproj @@ -41,7 +41,7 @@ - + diff --git a/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs b/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs index b394cdff1c590..55547e66244bc 100644 --- a/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs +++ b/dotnet/src/webdriver/Internal/StringSyntaxConstants.cs @@ -1,6 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Text; +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// namespace OpenQA.Selenium.Internal; From a2e177e50d5ba1d2092e9f38e959176d02a86d31 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 22 Nov 2025 01:36:12 -0500 Subject: [PATCH 13/13] Fix build once more --- dotnet/src/support/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index e0eded3bc2e15..9cc66665c7618 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -34,7 +34,7 @@ csharp_library( "UI/*.cs", ]) + [ ":assembly-info", - "//dotnet:source_files_support_needs_from_core" + "//dotnet:source_files_support_needs_from_core", ], out = "WebDriver.Support", langversion = "12.0", @@ -76,7 +76,7 @@ csharp_library( "UI/*.cs", ]) + [ ":assembly-info", - "//dotnet:source_files_support_needs_from_core" + "//dotnet:source_files_support_needs_from_core", ], out = "WebDriver.Support.StrongNamed", keyfile = "//dotnet:Selenium.snk",