Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Modules.Network.FetchErrorEventArgs))]
[JsonSerializable(typeof(Modules.Network.AuthRequiredEventArgs))]

[JsonSerializable(typeof(Modules.Script.Target.Realm), TypeInfoPropertyName = "Script_Target_Realm")]
[JsonSerializable(typeof(Modules.Script.Target.Context), TypeInfoPropertyName = "Script_Target_Context")]

[JsonSerializable(typeof(Modules.Script.AddPreloadScriptCommand))]
[JsonSerializable(typeof(Modules.Script.AddPreloadScriptResult))]
[JsonSerializable(typeof(Modules.Script.DisownCommand))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? opt

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

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

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

if (targetOptions is not null)
{
Expand Down
17 changes: 8 additions & 9 deletions dotnet/src/webdriver/BiDi/Modules/Script/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@

namespace OpenQA.Selenium.BiDi.Modules.Script;

[JsonDerivedType(typeof(Realm))]
[JsonDerivedType(typeof(Context))]
public abstract record Target
{
public record Realm([property: JsonPropertyName("realm")] Script.Realm Target) : Target;
[JsonDerivedType(typeof(RealmTarget))]
[JsonDerivedType(typeof(ContextTarget))]
public abstract record Target;

public record RealmTarget(Realm Realm) : Target;

public record Context([property: JsonPropertyName("context")] BrowsingContext.BrowsingContext Target) : Target
{
public string? Sandbox { get; set; }
}
public record ContextTarget(BrowsingContext.BrowsingContext Context) : Target
{
public string? Sandbox { get; set; }
}

public class ContextTargetOptions
Expand Down
8 changes: 4 additions & 4 deletions dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ public async Task CanCallFunctionInARealm()

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

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

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

Assert.That(res1, Is.EqualTo(3));
Assert.That(res2, Is.EqualTo(5));
Expand Down
8 changes: 4 additions & 4 deletions dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public async Task CanEvaluateInARealm()

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

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

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

Assert.That(res1, Is.EqualTo(3));
Assert.That(res2, Is.EqualTo(5));
Expand Down
Loading