Skip to content

Commit e9c2117

Browse files
Merge branch 'trunk' into driver-options-tostring
2 parents c96813f + 3906742 commit e9c2117

File tree

26 files changed

+129
-138
lines changed

26 files changed

+129
-138
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bazel_dep(name = "protobuf", version = "21.7", dev_dependency = True, repo_name
1717
# Required for rules_rust to import the crates properly
1818
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)
1919

20-
bazel_dep(name = "rules_dotnet", version = "0.16.0")
20+
bazel_dep(name = "rules_dotnet", version = "0.16.1")
2121
bazel_dep(name = "rules_java", version = "7.11.1")
2222
bazel_dep(name = "rules_jvm_external", version = "6.3")
2323
bazel_dep(name = "rules_nodejs", version = "6.3.0")

dotnet/src/webdriver/Remote/RemoteSessionSettings.cs

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

2020
using OpenQA.Selenium.Remote;
2121
using System;
22-
using System.Collections;
2322
using System.Collections.Generic;
2423
using System.Globalization;
2524
using System.Text.Json;
@@ -71,18 +70,12 @@ public RemoteSessionSettings(DriverOptions mustMatchDriverOptions, params Driver
7170
/// <summary>
7271
/// Gets a value indicating the options that must be matched by the remote end to create a session.
7372
/// </summary>
74-
internal DriverOptions MustMatchDriverOptions
75-
{
76-
get { return this.mustMatchDriverOptions; }
77-
}
73+
internal DriverOptions MustMatchDriverOptions => this.mustMatchDriverOptions;
7874

7975
/// <summary>
8076
/// Gets a value indicating the number of options that may be matched by the remote end to create a session.
8177
/// </summary>
82-
internal int FirstMatchOptionsCount
83-
{
84-
get { return this.firstMatchOptions.Count; }
85-
}
78+
internal int FirstMatchOptionsCount => this.firstMatchOptions.Count;
8679

8780
/// <summary>
8881
/// Gets the capability value with the specified name.
@@ -92,6 +85,7 @@ internal int FirstMatchOptionsCount
9285
/// <exception cref="ArgumentException">
9386
/// The specified capability name is not in the set of capabilities.
9487
/// </exception>
88+
/// <exception cref="ArgumentNullException">If <paramref name="capabilityName"/> is null.</exception>
9589
public object this[string capabilityName]
9690
{
9791
get
@@ -121,18 +115,10 @@ public object this[string capabilityName]
121115
/// </summary>
122116
/// <param name="settingName">The name of the setting to set.</param>
123117
/// <param name="settingValue">The value of the setting.</param>
124-
/// <remarks>
125-
/// The value to be set must be serializable to JSON for transmission
126-
/// across the wire to the remote end. To be JSON-serializable, the value
127-
/// must be a string, a numeric value, a boolean value, an object that
128-
/// implmeents <see cref="IEnumerable"/> that contains JSON-serializable
129-
/// objects, or a <see cref="Dictionary{TKey, TValue}"/> where the keys
130-
/// are strings and the values are JSON-serializable.
131-
/// </remarks>
132118
/// <exception cref="ArgumentException">
133-
/// Thrown if the setting name is null, the empty string, or one of the
134-
/// reserved names of metadata settings; or if the setting value is not
135-
/// JSON serializable.
119+
/// <para>If the setting name is null or empty.</para>
120+
/// <para>-or-</para>
121+
/// <para>If one of the reserved names of metadata settings.</para>
136122
/// </exception>
137123
public void AddMetadataSetting(string settingName, object settingValue)
138124
{
@@ -146,11 +132,6 @@ public void AddMetadataSetting(string settingName, object settingValue)
146132
throw new ArgumentException(string.Format("'{0}' is a reserved name for a metadata setting, and cannot be used as a name.", settingName), nameof(settingName));
147133
}
148134

149-
if (!this.IsJsonSerializable(settingValue))
150-
{
151-
throw new ArgumentException("Metadata setting value must be JSON serializable.", nameof(settingValue));
152-
}
153-
154135
this.remoteMetadataSettings[settingName] = settingValue;
155136
}
156137

@@ -161,9 +142,9 @@ public void AddMetadataSetting(string settingName, object settingValue)
161142
/// <param name="options">The <see cref="DriverOptions"/> to add to the list of "first matched" options.</param>
162143
public void AddFirstMatchDriverOption(DriverOptions options)
163144
{
164-
if (mustMatchDriverOptions != null)
145+
if (this.mustMatchDriverOptions != null)
165146
{
166-
DriverOptionsMergeResult mergeResult = mustMatchDriverOptions.GetMergeResult(options);
147+
DriverOptionsMergeResult mergeResult = this.mustMatchDriverOptions.GetMergeResult(options);
167148
if (mergeResult.IsMergeConflict)
168149
{
169150
string msg = string.Format(CultureInfo.InvariantCulture, "You cannot request the same capability in both must-match and first-match capabilities. You are attempting to add a first-match driver options object that defines a capability, '{0}', that is already defined in the must-match driver options.", mergeResult.MergeConflictOptionName);
@@ -297,58 +278,13 @@ private IDictionary<string, object> GetAlwaysMatchOptionsAsSerializableDictionar
297278

298279
private List<object> GetFirstMatchOptionsAsSerializableList()
299280
{
300-
List<object> optionsMatches = new List<object>();
281+
List<object> optionsMatches = new List<object>(this.firstMatchOptions.Count);
301282
foreach (DriverOptions options in this.firstMatchOptions)
302283
{
303284
optionsMatches.Add(options.ToDictionary());
304285
}
305286

306287
return optionsMatches;
307288
}
308-
309-
private bool IsJsonSerializable(object arg)
310-
{
311-
IEnumerable argAsEnumerable = arg as IEnumerable;
312-
IDictionary argAsDictionary = arg as IDictionary;
313-
314-
if (arg is string || arg is float || arg is double || arg is int || arg is long || arg is bool || arg == null)
315-
{
316-
return true;
317-
}
318-
else if (argAsDictionary != null)
319-
{
320-
foreach (object key in argAsDictionary.Keys)
321-
{
322-
if (!(key is string))
323-
{
324-
return false;
325-
}
326-
}
327-
328-
foreach (object value in argAsDictionary.Values)
329-
{
330-
if (!IsJsonSerializable(value))
331-
{
332-
return false;
333-
}
334-
}
335-
}
336-
else if (argAsEnumerable != null)
337-
{
338-
foreach (object item in argAsEnumerable)
339-
{
340-
if (!IsJsonSerializable(item))
341-
{
342-
return false;
343-
}
344-
}
345-
}
346-
else
347-
{
348-
return false;
349-
}
350-
351-
return true;
352-
}
353289
}
354290
}

dotnet/test/remote/RemoteSessionCreationTests.cs

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

2020
using NUnit.Framework;
21+
using System.Collections.Generic;
22+
using System.Text.Json;
23+
using System.Text.Json.Nodes;
2124

2225
namespace OpenQA.Selenium.Remote
2326
{
@@ -68,5 +71,66 @@ public void CreateEdgeRemoteSession()
6871
edge.Quit();
6972
}
7073
}
74+
75+
[Test]
76+
public void ShouldSetRemoteSessionSettingsMetadata()
77+
{
78+
var settings = new RemoteSessionSettings();
79+
80+
Assert.That(settings.HasCapability("a"), Is.False);
81+
82+
settings.AddMetadataSetting("a", null);
83+
Assert.That(settings.HasCapability("a"));
84+
Assert.That(settings.GetCapability("a"), Is.Null);
85+
86+
settings.AddMetadataSetting("a", true);
87+
Assert.That(settings.HasCapability("a"));
88+
Assert.That(settings.GetCapability("a"), Is.True);
89+
90+
settings.AddMetadataSetting("a", false);
91+
Assert.That(settings.HasCapability("a"));
92+
Assert.That(settings.GetCapability("a"), Is.False);
93+
94+
settings.AddMetadataSetting("a", 123);
95+
Assert.That(settings.HasCapability("a"));
96+
Assert.That(settings.GetCapability("a"), Is.TypeOf<int>().And.EqualTo(123));
97+
98+
settings.AddMetadataSetting("a", 123f);
99+
Assert.That(settings.HasCapability("a"));
100+
Assert.That(settings.GetCapability("a"), Is.TypeOf<float>().And.EqualTo(123f));
101+
102+
settings.AddMetadataSetting("a", 123d);
103+
Assert.That(settings.HasCapability("a"));
104+
Assert.That(settings.GetCapability("a"), Is.TypeOf<double>().And.EqualTo(123d));
105+
106+
JsonNode trueName = JsonValue.Create(true);
107+
settings.AddMetadataSetting("a", trueName);
108+
Assert.That(settings.HasCapability("a"));
109+
Assert.That(settings.GetCapability("a"), Is.InstanceOf<JsonNode>().And.EqualTo(trueName).Using<JsonNode>(JsonNode.DeepEquals));
110+
111+
var reader = new Utf8JsonReader("false"u8);
112+
JsonElement trueElement = JsonElement.ParseValue(ref reader);
113+
114+
settings.AddMetadataSetting("a", trueElement);
115+
Assert.That(settings.HasCapability("a"));
116+
Assert.That(settings.GetCapability("a"), Is.TypeOf<JsonElement>().And.Matches<JsonElement>(static left =>
117+
{
118+
return left.ValueKind == JsonValueKind.False;
119+
}));
120+
121+
List<int> intValues = [1, 2, 3];
122+
settings.AddMetadataSetting("a", intValues);
123+
Assert.That(settings.HasCapability("a"));
124+
Assert.That(settings.GetCapability("a"), Is.TypeOf<List<int>>().And.EqualTo(intValues));
125+
126+
Dictionary<string, int> dictionaryValues = new Dictionary<string, int>
127+
{
128+
{"value1", 1 },
129+
{"value2", 1 },
130+
};
131+
settings.AddMetadataSetting("a", dictionaryValues);
132+
Assert.That(settings.HasCapability("a"));
133+
Assert.That(settings.GetCapability("a"), Is.TypeOf<Dictionary<string, int>>().And.EqualTo(dictionaryValues));
134+
}
71135
}
72136
}

rb/Gemfile.lock

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ PATH
1313
GEM
1414
remote: https://rubygems.org/
1515
specs:
16-
activesupport (7.2.1.2)
16+
activesupport (7.2.2)
1717
base64
18+
benchmark (>= 0.3)
1819
bigdecimal
1920
concurrent-ruby (~> 1.0, >= 1.3.1)
2021
connection_pool (>= 2.2.5)
@@ -28,6 +29,7 @@ GEM
2829
public_suffix (>= 2.0.2, < 7.0)
2930
ast (2.4.2)
3031
base64 (0.2.0)
32+
benchmark (0.4.0)
3133
bigdecimal (3.1.8)
3234
bigdecimal (3.1.8-java)
3335
concurrent-ruby (1.3.4)
@@ -45,7 +47,7 @@ GEM
4547
ffi (1.17.0)
4648
ffi (1.17.0-java)
4749
ffi (1.17.0-x86_64-darwin)
48-
fileutils (1.7.2)
50+
fileutils (1.7.3)
4951
git (1.19.1)
5052
addressable (~> 2.8)
5153
rchardet (~> 1.8)
@@ -58,21 +60,21 @@ GEM
5860
rdoc (>= 4.0.0)
5961
reline (>= 0.4.2)
6062
jar-dependencies (0.4.1)
61-
json (2.7.5)
62-
json (2.7.5-java)
63+
json (2.8.1)
64+
json (2.8.1-java)
6365
language_server-protocol (3.17.0.3)
6466
listen (3.9.0)
6567
rb-fsevent (~> 0.10, >= 0.10.3)
6668
rb-inotify (~> 0.9, >= 0.9.10)
6769
logger (1.6.1)
6870
minitest (5.25.1)
6971
parallel (1.26.3)
70-
parser (3.3.5.0)
72+
parser (3.3.6.0)
7173
ast (~> 2.4.1)
7274
racc
73-
psych (5.1.2)
75+
psych (5.2.0)
7476
stringio
75-
psych (5.1.2-java)
77+
psych (5.2.0-java)
7678
jar-dependencies (>= 0.1.7)
7779
public_suffix (6.0.1)
7880
racc (1.8.1)
@@ -89,7 +91,7 @@ GEM
8991
rdoc (6.7.0)
9092
psych (>= 4.0.0)
9193
regexp_parser (2.9.2)
92-
reline (0.5.10)
94+
reline (0.5.11)
9395
io-console (~> 0.5)
9496
rexml (3.3.9)
9597
rspec (3.13.0)
@@ -105,7 +107,7 @@ GEM
105107
diff-lcs (>= 1.2.0, < 2.0)
106108
rspec-support (~> 3.13.0)
107109
rspec-support (3.13.1)
108-
rubocop (1.67.0)
110+
rubocop (1.68.0)
109111
json (~> 2.3)
110112
language_server-protocol (>= 3.17.0)
111113
parallel (~> 1.10)
@@ -115,7 +117,7 @@ GEM
115117
rubocop-ast (>= 1.32.2, < 2.0)
116118
ruby-progressbar (~> 1.7)
117119
unicode-display_width (>= 2.4.0, < 3.0)
118-
rubocop-ast (1.33.0)
120+
rubocop-ast (1.34.1)
119121
parser (>= 3.3.1.0)
120122
rubocop-capybara (2.21.0)
121123
rubocop (~> 1.41)
@@ -151,7 +153,7 @@ GEM
151153
securerandom (>= 0.1)
152154
strscan (>= 1.0.0)
153155
terminal-table (>= 2, < 4)
154-
stringio (3.1.1)
156+
stringio (3.1.2)
155157
strscan (3.1.0)
156158
strscan (3.1.0-java)
157159
terminal-table (3.0.2)
@@ -163,7 +165,7 @@ GEM
163165
addressable (>= 2.8.0)
164166
crack (>= 0.3.2)
165167
hashdiff (>= 0.4.0, < 2.0.0)
166-
webrick (1.8.2)
168+
webrick (1.9.0)
167169
websocket (1.2.11)
168170
yard (0.9.37)
169171

rb/lib/selenium/webdriver/bidi/log_handler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def initialize(bidi)
3030
end
3131

3232
# @return [int] id of the handler
33+
# steep:ignore:start
3334
def add_message_handler(type)
3435
subscribe_log_entry unless @log_entry_subscribed
3536
@bidi.add_callback('log.entryAdded') do |params|
@@ -39,6 +40,7 @@ def add_message_handler(type)
3940
end
4041
end
4142
end
43+
# steep:ignore:end
4244

4345
# @param [int] id of the handler previously added
4446
def remove_message_handler(id)

rb/lib/selenium/webdriver/bidi/struct.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def camel_to_snake(camel_str)
3737
end
3838
end
3939
end
40-
end
41-
42-
# BiDi
40+
end # BiDi
4341
end # WebDriver
4442
end # Selenium

rb/lib/selenium/webdriver/common/error.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ def initialize(msg = '')
5050
super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg)
5151
end
5252

53+
# steep:ignore:start
5354
def class_name
54-
self.class.name&.split('::')&.last&.to_sym
55+
self.class.name.split('::')&.last&.to_sym
5556
end
57+
# steep:ignore:end
5658
end
5759

5860
#

rb/lib/selenium/webdriver/common/fedcm/account.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class Account
3030
attr_reader :account_id, :email, :name, :given_name, :picture_url,
3131
:idp_config_url, :login_state, :terms_of_service_url, :privacy_policy_url
3232

33-
# Initializes a new account with the provided attributes.
34-
#
35-
# @param [Hash]
33+
# steep:ignore:start
3634
def initialize(**args)
3735
@account_id = args['accountId']
3836
@email = args['email']
@@ -44,6 +42,7 @@ def initialize(**args)
4442
@terms_of_service_url = args['termsOfServiceUrl']
4543
@privacy_policy_url = args['privacyPolicyUrl']
4644
end
45+
# steep:ignore:end
4746
end # Account
4847
end # FedCM
4948
end # WebDriver

0 commit comments

Comments
 (0)