Skip to content

Commit c4eaa87

Browse files
nvborisenkosandeepsuryaprasad
authored andcommitted
[dotnet] [bidi] Make script Target as not nested (SeleniumHQ#15436)
1 parent 9cc803c commit c4eaa87

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
139139
[JsonSerializable(typeof(Modules.Network.FetchErrorEventArgs))]
140140
[JsonSerializable(typeof(Modules.Network.AuthRequiredEventArgs))]
141141

142-
[JsonSerializable(typeof(Modules.Script.Target.Realm), TypeInfoPropertyName = "Script_Target_Realm")]
143-
[JsonSerializable(typeof(Modules.Script.Target.Context), TypeInfoPropertyName = "Script_Target_Context")]
144-
145142
[JsonSerializable(typeof(Modules.Script.AddPreloadScriptCommand))]
146143
[JsonSerializable(typeof(Modules.Script.AddPreloadScriptResult))]
147144
[JsonSerializable(typeof(Modules.Script.DisownCommand))]

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? opt
4646

4747
public Task<EvaluateResult.Success> EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null)
4848
{
49-
var contextTarget = new Target.Context(context);
49+
var contextTarget = new ContextTarget(context);
5050

5151
if (targetOptions is not null)
5252
{
@@ -65,7 +65,7 @@ public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? opt
6565

6666
public Task<EvaluateResult.Success> CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null)
6767
{
68-
var contextTarget = new Target.Context(context);
68+
var contextTarget = new ContextTarget(context);
6969

7070
if (targetOptions is not null)
7171
{

dotnet/src/webdriver/BiDi/Modules/Script/Target.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121

2222
namespace OpenQA.Selenium.BiDi.Modules.Script;
2323

24-
[JsonDerivedType(typeof(Realm))]
25-
[JsonDerivedType(typeof(Context))]
26-
public abstract record Target
27-
{
28-
public record Realm([property: JsonPropertyName("realm")] Script.Realm Target) : Target;
24+
[JsonDerivedType(typeof(RealmTarget))]
25+
[JsonDerivedType(typeof(ContextTarget))]
26+
public abstract record Target;
27+
28+
public record RealmTarget(Realm Realm) : Target;
2929

30-
public record Context([property: JsonPropertyName("context")] BrowsingContext.BrowsingContext Target) : Target
31-
{
32-
public string? Sandbox { get; set; }
33-
}
30+
public record ContextTarget(BrowsingContext.BrowsingContext Context) : Target
31+
{
32+
public string? Sandbox { get; set; }
3433
}
3534

3635
public class ContextTargetOptions

dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ public async Task CanCallFunctionInARealm()
210210

211211
var realms = await bidi.Script.GetRealmsAsync();
212212

213-
await bidi.Script.CallFunctionAsync("() => { window.foo = 3; }", true, new Target.Realm(realms[0].Realm));
214-
await bidi.Script.CallFunctionAsync("() => { window.foo = 5; }", true, new Target.Realm(realms[1].Realm));
213+
await bidi.Script.CallFunctionAsync("() => { window.foo = 3; }", true, new RealmTarget(realms[0].Realm));
214+
await bidi.Script.CallFunctionAsync("() => { window.foo = 5; }", true, new RealmTarget(realms[1].Realm));
215215

216-
var res1 = await bidi.Script.CallFunctionAsync<int>("() => window.foo", true, new Target.Realm(realms[0].Realm));
217-
var res2 = await bidi.Script.CallFunctionAsync<int>("() => window.foo", true, new Target.Realm(realms[1].Realm));
216+
var res1 = await bidi.Script.CallFunctionAsync<int>("() => window.foo", true, new RealmTarget(realms[0].Realm));
217+
var res2 = await bidi.Script.CallFunctionAsync<int>("() => window.foo", true, new RealmTarget(realms[1].Realm));
218218

219219
Assert.That(res1, Is.EqualTo(3));
220220
Assert.That(res2, Is.EqualTo(5));

dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public async Task CanEvaluateInARealm()
116116

117117
var realms = await bidi.Script.GetRealmsAsync();
118118

119-
await bidi.Script.EvaluateAsync("window.foo = 3", true, new Target.Realm(realms[0].Realm));
120-
await bidi.Script.EvaluateAsync("window.foo = 5", true, new Target.Realm(realms[1].Realm));
119+
await bidi.Script.EvaluateAsync("window.foo = 3", true, new RealmTarget(realms[0].Realm));
120+
await bidi.Script.EvaluateAsync("window.foo = 5", true, new RealmTarget(realms[1].Realm));
121121

122-
var res1 = await bidi.Script.EvaluateAsync<int>("window.foo", true, new Target.Realm(realms[0].Realm));
123-
var res2 = await bidi.Script.EvaluateAsync<int>("window.foo", true, new Target.Realm(realms[1].Realm));
122+
var res1 = await bidi.Script.EvaluateAsync<int>("window.foo", true, new RealmTarget(realms[0].Realm));
123+
var res2 = await bidi.Script.EvaluateAsync<int>("window.foo", true, new RealmTarget(realms[1].Realm));
124124

125125
Assert.That(res1, Is.EqualTo(3));
126126
Assert.That(res2, Is.EqualTo(5));

0 commit comments

Comments
 (0)