Skip to content

Commit 8001ffa

Browse files
committed
Merge branch 'script-callbacks' of https://github.com/RenderMichael/selenium into script-callbacks
2 parents d4605ef + d2537ee commit 8001ffa

File tree

28 files changed

+127
-423
lines changed

28 files changed

+127
-423
lines changed

.bazelrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ try-import %workspace%/.bazelrc.windows.local
88
# https://github.com/bazelbuild/bazel/issues/20369
99
# https://github.com/bazelbuild/bazel/issues/21491
1010

11-
common --enable_bzlmod --lockfile_mode=off
11+
common --lockfile_mode=off
12+
13+
# Prepare for Bazel 8. These become the default in 8.0.0
14+
common --incompatible_disallow_empty_glob
15+
common --incompatible_use_plus_in_repo_names
1216

1317
# Ensure Windows support is accurate.
1418

dotnet/src/support/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ csharp_library(
3131
"*.cs",
3232
"Events/*.cs",
3333
"Extensions/*.cs",
34-
"PageObjects/**/*.cs",
3534
"UI/*.cs",
3635
]) + [":assembly-info"],
3736
out = "WebDriver.Support",
@@ -71,7 +70,6 @@ csharp_library(
7170
"*.cs",
7271
"Events/*.cs",
7372
"Extensions/*.cs",
74-
"PageObjects/**/*.cs",
7573
"UI/*.cs",
7674
]) + [":assembly-info"],
7775
out = "WebDriver.Support.StrongNamed",

dotnet/src/webdriver/CommandInfo.cs

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

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium
2325
{
2426
/// <summary>
@@ -45,7 +47,7 @@ public override int GetHashCode()
4547
/// </summary>
4648
/// <param name="obj">The <see cref="CommandInfo"/> to compare to this instance.</param>
4749
/// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="CommandInfo"/> and its value is the same as this instance; otherwise, <see langword="false"/>. If <paramref name="obj"/> is <see langword="null"/>, the method returns <see langword="false"/>.</returns>
48-
public override bool Equals(object obj)
50+
public override bool Equals(object? obj)
4951
{
5052
return this.Equals(obj as CommandInfo);
5153
}
@@ -55,15 +57,15 @@ public override bool Equals(object obj)
5557
/// </summary>
5658
/// <param name="other">The <see cref="CommandInfo"/> to compare to this instance.</param>
5759
/// <returns><see langword="true"/> if the value of the <paramref name="other"/> parameter is the same as this instance; otherwise, <see langword="false"/>. If <paramref name="other"/> is <see langword="null"/>, the method returns <see langword="false"/>.</returns>
58-
public bool Equals(CommandInfo other)
60+
public bool Equals(CommandInfo? other)
5961
{
6062
if (other is null)
6163
{
6264
return false;
6365
}
6466

6567
// Optimization for a common success case.
66-
if (Object.ReferenceEquals(this, other))
68+
if (object.ReferenceEquals(this, other))
6769
{
6870
return true;
6971
}
@@ -86,7 +88,7 @@ public bool Equals(CommandInfo other)
8688
/// <param name="left">The first <see cref="CommandInfo"/> object to compare.</param>
8789
/// <param name="right">The second <see cref="CommandInfo"/> object to compare.</param>
8890
/// <returns><see langword="true"/> if the value of <paramref name="left"/> is the same as the value of <paramref name="right"/>; otherwise, <see langword="false"/>.</returns>
89-
public static bool operator ==(CommandInfo left, CommandInfo right)
91+
public static bool operator ==(CommandInfo? left, CommandInfo? right)
9092
{
9193
if (left is null)
9294
{
@@ -107,7 +109,7 @@ public bool Equals(CommandInfo other)
107109
/// <param name="left">The first <see cref="CommandInfo"/> object to compare.</param>
108110
/// <param name="right">The second <see cref="CommandInfo"/> object to compare.</param>
109111
/// <returns><see langword="true"/> if the value of <paramref name="left"/> is different from the value of <paramref name="right"/>; otherwise, <see langword="false"/>.</returns>
110-
public static bool operator !=(CommandInfo left, CommandInfo right)
112+
public static bool operator !=(CommandInfo? left, CommandInfo? right)
111113
{
112114
return !(left == right);
113115
}

dotnet/src/webdriver/Firefox/FirefoxDriver.cs

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// under the License.
1818
// </copyright>
1919

20-
using OpenQA.Selenium.DevTools;
2120
using OpenQA.Selenium.Remote;
2221
using System;
2322
using System.Collections.Generic;
@@ -71,11 +70,8 @@ namespace OpenQA.Selenium.Firefox
7170
/// }
7271
/// </code>
7372
/// </example>
74-
public class FirefoxDriver : WebDriver, IDevTools
73+
public class FirefoxDriver : WebDriver
7574
{
76-
private const int FirefoxDevToolsProtocolVersion = 85;
77-
private const string FirefoxDevToolsCapabilityName = "moz:debuggerAddress";
78-
7975
/// <summary>
8076
/// Command for setting the command context of a Firefox driver.
8177
/// </summary>
@@ -110,8 +106,6 @@ public class FirefoxDriver : WebDriver, IDevTools
110106
{ GetFullPageScreenshotCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/screenshot/full") }
111107
};
112108

113-
private DevToolsSession devToolsSession;
114-
115109
/// <summary>
116110
/// Initializes a new instance of the <see cref="FirefoxDriver"/> class.
117111
/// </summary>
@@ -244,14 +238,6 @@ public override IFileDetector FileDetector
244238
set { }
245239
}
246240

247-
/// <summary>
248-
/// Gets a value indicating whether a DevTools session is active.
249-
/// </summary>
250-
public bool HasActiveDevToolsSession
251-
{
252-
get { return this.devToolsSession != null; }
253-
}
254-
255241
/// <summary>
256242
/// Sets the command context used when issuing commands to geckodriver.
257243
/// </summary>
@@ -389,68 +375,6 @@ public Screenshot GetFullPageScreenshot()
389375
return new Screenshot(base64);
390376
}
391377

392-
/// <summary>
393-
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
394-
/// </summary>
395-
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
396-
[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
397-
public DevToolsSession GetDevToolsSession()
398-
{
399-
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = FirefoxDevToolsProtocolVersion });
400-
}
401-
402-
/// <summary>
403-
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
404-
/// </summary>
405-
/// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
406-
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
407-
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
408-
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
409-
{
410-
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = devToolsProtocolVersion });
411-
}
412-
413-
/// <summary>
414-
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
415-
/// </summary>
416-
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
417-
[Obsolete("CDP support for Firefox is deprecated and will be removed in future versions. Please switch to WebDriver BiDi.")]
418-
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
419-
{
420-
if (this.devToolsSession == null)
421-
{
422-
if (!this.Capabilities.HasCapability(FirefoxDevToolsCapabilityName))
423-
{
424-
throw new WebDriverException("Cannot find " + FirefoxDevToolsCapabilityName + " capability for driver");
425-
}
426-
427-
string debuggerAddress = this.Capabilities.GetCapability(FirefoxDevToolsCapabilityName).ToString();
428-
try
429-
{
430-
DevToolsSession session = new DevToolsSession(debuggerAddress, options);
431-
Task.Run(async () => await session.StartSession()).GetAwaiter().GetResult();
432-
this.devToolsSession = session;
433-
}
434-
catch (Exception e)
435-
{
436-
throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e);
437-
}
438-
}
439-
440-
return this.devToolsSession;
441-
}
442-
443-
/// <summary>
444-
/// Closes a DevTools session.
445-
/// </summary>
446-
public void CloseDevToolsSession()
447-
{
448-
if (this.devToolsSession != null)
449-
{
450-
Task.Run(async () => await this.devToolsSession.StopSession(true)).GetAwaiter().GetResult();
451-
}
452-
}
453-
454378
/// <summary>
455379
/// In derived classes, the <see cref="PrepareEnvironment"/> method prepares the environment for test execution.
456380
/// </summary>
@@ -467,15 +391,6 @@ protected virtual void PrepareEnvironment()
467391
/// disposing the object; otherwise <see langword="false"/>.</param>
468392
protected override void Dispose(bool disposing)
469393
{
470-
if (disposing)
471-
{
472-
if (this.devToolsSession != null)
473-
{
474-
this.devToolsSession.Dispose();
475-
this.devToolsSession = null;
476-
}
477-
}
478-
479394
base.Dispose(disposing);
480395
}
481396

dotnet/src/webdriver/HttpCommandInfo.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System;
2121
using System.Globalization;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium
2426
{
2527
/// <summary>
@@ -44,42 +46,33 @@ public class HttpCommandInfo : CommandInfo
4446

4547
private const string SessionIdPropertyName = "sessionId";
4648

47-
private string resourcePath;
48-
private string method;
49-
5049
/// <summary>
5150
/// Initializes a new instance of the <see cref="HttpCommandInfo"/> class
5251
/// </summary>
5352
/// <param name="method">Method of the Command</param>
5453
/// <param name="resourcePath">Relative URL path to the resource used to execute the command</param>
5554
public HttpCommandInfo(string method, string resourcePath)
5655
{
57-
this.resourcePath = resourcePath;
58-
this.method = method;
56+
this.ResourcePath = resourcePath;
57+
this.Method = method;
5958
}
6059

6160
/// <summary>
6261
/// Gets the URL representing the path to the resource.
6362
/// </summary>
64-
public string ResourcePath
65-
{
66-
get { return this.resourcePath; }
67-
}
63+
public string ResourcePath { get; }
6864

6965
/// <summary>
7066
/// Gets the HTTP method associated with the command.
7167
/// </summary>
72-
public string Method
73-
{
74-
get { return this.method; }
75-
}
68+
public string Method { get; }
7669

7770
/// <summary>
7871
/// Gets the unique identifier for this command within the scope of its protocol definition
7972
/// </summary>
8073
public override string CommandIdentifier
8174
{
82-
get { return string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.method, this.resourcePath); }
75+
get { return string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.Method, this.ResourcePath); }
8376
}
8477

8578
/// <summary>
@@ -93,7 +86,7 @@ public override string CommandIdentifier
9386
/// substituted for the tokens in the template.</returns>
9487
public Uri CreateCommandUri(Uri baseUri, Command commandToExecute)
9588
{
96-
string[] urlParts = this.resourcePath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
89+
string[] urlParts = this.ResourcePath.Split(["/"], StringSplitOptions.RemoveEmptyEntries);
9790
for (int i = 0; i < urlParts.Length; i++)
9891
{
9992
string urlPart = urlParts[i];
@@ -103,13 +96,11 @@ public Uri CreateCommandUri(Uri baseUri, Command commandToExecute)
10396
}
10497
}
10598

106-
Uri fullUri;
10799
string relativeUrlString = string.Join("/", urlParts);
108100
Uri relativeUri = new Uri(relativeUrlString, UriKind.Relative);
109-
bool uriCreateSucceeded = Uri.TryCreate(baseUri, relativeUri, out fullUri);
110-
if (!uriCreateSucceeded)
101+
if (!Uri.TryCreate(baseUri, relativeUri, out Uri? fullUri))
111102
{
112-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to create URI from base {0} and relative path {1}", baseUri == null ? string.Empty : baseUri.ToString(), relativeUrlString));
103+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to create URI from base {0} and relative path {1}", baseUri?.ToString(), relativeUrlString));
113104
}
114105

115106
return fullUri;
@@ -133,11 +124,11 @@ private static string GetCommandPropertyValue(string propertyName, Command comma
133124
{
134125
// Extract the URL parameter, and remove it from the parameters dictionary
135126
// so it doesn't get transmitted as a JSON parameter.
136-
if (commandToExecute.Parameters.ContainsKey(propertyName))
127+
if (commandToExecute.Parameters.TryGetValue(propertyName, out var propertyValueObject))
137128
{
138-
if (commandToExecute.Parameters[propertyName] != null)
129+
if (propertyValueObject != null)
139130
{
140-
propertyValue = commandToExecute.Parameters[propertyName].ToString();
131+
propertyValue = propertyValueObject.ToString()!;
141132
commandToExecute.Parameters.Remove(propertyName);
142133
}
143134
}

dotnet/src/webdriver/ICommandExecutor.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
// </copyright>
1919

2020
using System;
21+
using System.Diagnostics.CodeAnalysis;
2122
using System.Threading.Tasks;
2223

24+
#nullable enable
25+
2326
namespace OpenQA.Selenium
2427
{
2528
/// <summary>
@@ -31,15 +34,16 @@ public interface ICommandExecutor : IDisposable
3134
/// Attempts to add a command to the repository of commands known to this executor.
3235
/// </summary>
3336
/// <param name="commandName">The name of the command to attempt to add.</param>
34-
/// <param name="info">The <see cref="CommandInfo"/> describing the commnd to add.</param>
37+
/// <param name="info">The <see cref="CommandInfo"/> describing the command to add.</param>
3538
/// <returns><see langword="true"/> if the new command has been added successfully; otherwise, <see langword="false"/>.</returns>
36-
bool TryAddCommand(string commandName, CommandInfo info);
39+
bool TryAddCommand(string commandName, [NotNullWhen(true)] CommandInfo? info);
3740

3841
/// <summary>
3942
/// Executes a command
4043
/// </summary>
4144
/// <param name="commandToExecute">The command you wish to execute</param>
4245
/// <returns>A response from the browser</returns>
46+
/// <exception cref="ArgumentNullException">If <paramref name="commandToExecute"/> is <see langword="null"/>.</exception>
4347
Response Execute(Command commandToExecute);
4448

4549

@@ -48,6 +52,7 @@ public interface ICommandExecutor : IDisposable
4852
/// </summary>
4953
/// <param name="commandToExecute">The command you wish to execute</param>
5054
/// <returns>A task object representing the asynchronous operation</returns>
55+
/// <exception cref="ArgumentNullException">If <paramref name="commandToExecute"/> is <see langword="null"/>.</exception>
5156
Task<Response> ExecuteAsync(Command commandToExecute);
5257
}
5358
}

dotnet/src/webdriver/ICustomDriverCommandExecutor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// </copyright>
1919

2020
using System.Collections.Generic;
21+
using System.Diagnostics.CodeAnalysis;
22+
23+
#nullable enable
2124

2225
namespace OpenQA.Selenium
2326
{
@@ -32,7 +35,8 @@ public interface ICustomDriverCommandExecutor
3235
/// <param name="driverCommandToExecute">The name of the command to execute. The command name must be registered with the command executor, and must not be a command name known to this driver type.</param>
3336
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
3437
/// <returns>An object that contains the value returned by the command, if any.</returns>
35-
object ExecuteCustomDriverCommand(string driverCommandToExecute, Dictionary<string, object> parameters);
38+
/// <exception cref="WebDriverException">The command returned an exceptional value.</exception>
39+
object? ExecuteCustomDriverCommand(string driverCommandToExecute, Dictionary<string, object> parameters);
3640

3741
/// <summary>
3842
/// Registers a set of commands to be executed with this driver instance.
@@ -46,6 +50,6 @@ public interface ICustomDriverCommandExecutor
4650
/// <param name="commandName">The unique name of the command to register.</param>
4751
/// <param name="commandInfo">The <see cref="CommandInfo"/> object describing the command.</param>
4852
/// <returns><see langword="true"/> if the command was registered; otherwise, <see langword="false"/>.</returns>
49-
bool RegisterCustomDriverCommand(string commandName, CommandInfo commandInfo);
53+
bool RegisterCustomDriverCommand(string commandName, [NotNullWhen(true)] CommandInfo? commandInfo);
5054
}
5155
}

0 commit comments

Comments
 (0)