Skip to content

Commit 3170a49

Browse files
committed
[dotnet] add cdp v106 remove v103
1 parent a2b161a commit 3170a49

19 files changed

+948
-153
lines changed

dotnet/selenium-dotnet-version.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ SUPPORTED_NET_STANDARD_VERSIONS = ["netstandard2.0", "netstandard2.1", "net5.0"]
77

88
SUPPORTED_DEVTOOLS_VERSIONS = [
99
"v85",
10-
"v103",
1110
"v104",
1211
"v105",
12+
"v106",
1313
]
1414

1515
ASSEMBLY_COMPANY = "Selenium Committers"

dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public abstract class DevToolsDomains
3737
// added to this dictionary.
3838
private static readonly Dictionary<int, Type> SupportedDevToolsVersions = new Dictionary<int, Type>()
3939
{
40+
{ 106, typeof(V106.V106Domains) },
4041
{ 105, typeof(V105.V105Domains) },
4142
{ 104, typeof(V104.V104Domains) },
42-
{ 103, typeof(V103.V103Domains) },
4343
{ 85, typeof(V85.V85Domains) }
4444
};
4545

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
namespace OpenQA.Selenium.DevTools
3232
{
3333
/// <summary>
34-
/// Represents a WebSocket connection to a running DevTools instance that can be used to send
34+
/// Represents a WebSocket connection to a running DevTools instance that can be used to send
3535
/// commands and recieve events.
3636
///</summary>
3737
public class DevToolsSession : IDevToolsSession
3838
{
39-
public const int AutoDetectDevToolsProtocolVersion = 0;
39+
public const int AutoDetectDevToolsProtocolVersion = 106;
4040

4141
private readonly string debuggerEndpoint;
4242
private string websocketAddress;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// <copyright file="V106Domains.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text;
21+
22+
namespace OpenQA.Selenium.DevTools.V106
23+
{
24+
/// <summary>
25+
/// Class containing the domain implementation for version 106 of the DevTools Protocol.
26+
/// </summary>
27+
public class V106Domains : DevToolsDomains
28+
{
29+
private DevToolsSessionDomains domains;
30+
31+
public V106Domains(DevToolsSession session)
32+
{
33+
this.domains = new DevToolsSessionDomains(session);
34+
}
35+
36+
/// <summary>
37+
/// Gets the DevTools Protocol version for which this class is valid.
38+
/// </summary>
39+
public static int DevToolsVersion => 106;
40+
41+
/// <summary>
42+
/// Gets the version-specific domains for the DevTools session. This value must be cast to a version specific type to be at all useful.
43+
/// </summary>
44+
public override DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
45+
46+
/// <summary>
47+
/// Gets the object used for manipulating network information in the browser.
48+
/// </summary>
49+
public override DevTools.Network Network => new V106Network(domains.Network, domains.Fetch);
50+
51+
/// <summary>
52+
/// Gets the object used for manipulating the browser's JavaScript execution.
53+
/// </summary>
54+
public override JavaScript JavaScript => new V106JavaScript(domains.Runtime, domains.Page);
55+
56+
/// <summary>
57+
/// Gets the object used for manipulating DevTools Protocol targets.
58+
/// </summary>
59+
public override DevTools.Target Target => new V106Target(domains.Target);
60+
61+
/// <summary>
62+
/// Gets the object used for manipulating the browser's logs.
63+
/// </summary>
64+
public override DevTools.Log Log => new V106Log(domains.Log);
65+
}
66+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// <copyright file="V106JavaScript.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Threading.Tasks;
21+
using OpenQA.Selenium.DevTools.V106.Page;
22+
using OpenQA.Selenium.DevTools.V106.Runtime;
23+
24+
namespace OpenQA.Selenium.DevTools.V106
25+
{
26+
/// <summary>
27+
/// Class containing the JavaScript implementation for version 106 of the DevTools Protocol.
28+
/// </summary>
29+
public class V106JavaScript : JavaScript
30+
{
31+
private RuntimeAdapter runtime;
32+
private PageAdapter page;
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="V106JavaScript"/> class.
36+
/// </summary>
37+
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
38+
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
39+
public V106JavaScript(RuntimeAdapter runtime, PageAdapter page)
40+
{
41+
this.runtime = runtime;
42+
this.page = page;
43+
this.runtime.BindingCalled += OnRuntimeBindingCalled;
44+
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
45+
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
46+
}
47+
48+
/// <summary>
49+
/// Asynchronously enables the Runtime domain in the DevTools Protocol.
50+
/// </summary>
51+
/// <returns>A task that represents the asynchronous operation.</returns>
52+
public override async Task EnableRuntime()
53+
{
54+
await runtime.Enable();
55+
}
56+
57+
/// <summary>
58+
/// Asynchronously disables the Runtime domain in the DevTools Protocol.
59+
/// </summary>
60+
/// <returns>A task that represents the asynchronous operation.</returns>
61+
public override async Task DisableRuntime()
62+
{
63+
await runtime.Disable();
64+
}
65+
66+
/// <summary>
67+
/// Asynchronously enables the Page domain in the DevTools Protocol.
68+
/// </summary>
69+
/// <returns>A task that represents the asynchronous operation.</returns>
70+
public override async Task EnablePage()
71+
{
72+
await page.Enable();
73+
}
74+
75+
/// <summary>
76+
/// Asynchronously disables the Page domain in the DevTools Protocol.
77+
/// </summary>
78+
/// <returns>A task that represents the asynchronous operation.</returns>
79+
public override async Task DisablePage()
80+
{
81+
await page.Disable();
82+
}
83+
84+
/// <summary>
85+
/// Adds a binding to a specific JavaScript name.
86+
/// </summary>
87+
/// <param name="name">The name to which to bind to.</param>
88+
/// <returns>A task that represents the asynchronous operation.</returns>
89+
public override async Task AddBinding(string name)
90+
{
91+
await runtime.AddBinding(new AddBindingCommandSettings() { Name = name });
92+
}
93+
94+
/// <summary>
95+
/// Removes a binding from a specific JavaScript name.
96+
/// </summary>
97+
/// <param name="name">The name to which to remove the bind from.</param>
98+
/// <returns>A task that represents the asynchronous operation.</returns>
99+
public override async Task RemoveBinding(string name)
100+
{
101+
await runtime.RemoveBinding(new RemoveBindingCommandSettings() { Name = name });
102+
}
103+
104+
/// <summary>
105+
/// Adds a JavaScript snippet to evaluate when a new document is opened.
106+
/// </summary>
107+
/// <param name="script">The script to add to be evaluated when a new document is opened.</param>
108+
/// <returns>A task that represents the asynchronous operation. The task result contains the internal ID of the script.</returns>
109+
public override async Task<string> AddScriptToEvaluateOnNewDocument(string script)
110+
{
111+
var result = await page.AddScriptToEvaluateOnNewDocument(new AddScriptToEvaluateOnNewDocumentCommandSettings() { Source = script });
112+
return result.Identifier;
113+
}
114+
115+
/// <summary>
116+
/// Removes a JavaScript snippet from evaluate when a new document is opened.
117+
/// </summary>
118+
/// <param name="scriptId">The ID of the script to be removed.</param>
119+
/// <returns>A task that represents the asynchronous operation.</returns>
120+
public override async Task RemoveScriptToEvaluateOnNewDocument(string scriptId)
121+
{
122+
await page.RemoveScriptToEvaluateOnNewDocument(new RemoveScriptToEvaluateOnNewDocumentCommandSettings() { Identifier = scriptId });
123+
}
124+
125+
/// <summary>
126+
/// Evaluates a JavaScript snippet. It does not return a value.
127+
/// </summary>
128+
/// <param name="script">The script to evaluate</param>
129+
/// <returns>A task that represents the asynchronous operation.</returns>
130+
/// <remarks>
131+
/// This method is internal to the operation of pinned scripts in Selenium, and
132+
/// is therefore internal by design.
133+
/// </remarks>
134+
internal override async Task Evaluate(string script)
135+
{
136+
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script });
137+
}
138+
139+
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
140+
{
141+
BindingCalledEventArgs wrapped = new BindingCalledEventArgs()
142+
{
143+
ExecutionContextId = e.ExecutionContextId,
144+
Name = e.Name,
145+
Payload = e.Payload
146+
};
147+
148+
this.OnBindingCalled(wrapped);
149+
}
150+
151+
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
152+
{
153+
// TODO: Collect stack trace elements
154+
var wrapped = new ExceptionThrownEventArgs()
155+
{
156+
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
157+
Message = e.ExceptionDetails.Text
158+
};
159+
160+
this.OnExceptionThrown(wrapped);
161+
}
162+
163+
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
164+
{
165+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
166+
foreach (var arg in e.Args)
167+
{
168+
string argValue = null;
169+
if (arg.Value != null)
170+
{
171+
argValue = arg.Value.ToString();
172+
}
173+
args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue });
174+
}
175+
176+
var wrapped = new ConsoleApiCalledEventArgs()
177+
{
178+
Timestamp = new DateTime(1979, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
179+
Type = e.Type,
180+
Arguments = args.AsReadOnly()
181+
};
182+
183+
this.OnConsoleApiCalled(wrapped);
184+
}
185+
}
186+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// <copyright file="V106Log.cs" company="WebDriver Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text;
21+
using System.Threading;
22+
using System.Threading.Tasks;
23+
using OpenQA.Selenium.DevTools.V106.Log;
24+
25+
namespace OpenQA.Selenium.DevTools.V106
26+
{
27+
/// <summary>
28+
/// Class containing the browser's log as referenced by version 106 of the DevTools Protocol.
29+
/// </summary>
30+
public class V106Log : DevTools.Log
31+
{
32+
private LogAdapter adapter;
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="V106Log"/> class.
36+
/// </summary>
37+
/// <param name="adapter">The adapter for the Log domain.</param>
38+
public V106Log(LogAdapter adapter)
39+
{
40+
this.adapter = adapter;
41+
this.adapter.EntryAdded += OnAdapterEntryAdded;
42+
}
43+
44+
/// <summary>
45+
/// Asynchronously enables manipulation of the browser's log.
46+
/// </summary>
47+
/// <returns>A task that represents the asynchronous operation.</returns>
48+
public override async Task Enable()
49+
{
50+
await adapter.Enable();
51+
}
52+
53+
/// <summary>
54+
/// Asynchronously disables manipulation of the browser's log.
55+
/// </summary>
56+
/// <returns>A task that represents the asynchronous operation.</returns>
57+
public override async Task Disable()
58+
{
59+
await adapter.Disable();
60+
}
61+
62+
/// <summary>
63+
/// Asynchronously clears the browser's log.
64+
/// </summary>
65+
/// <returns>A task that represents the asynchronous operation.</returns>
66+
public override async Task Clear()
67+
{
68+
await adapter.Clear();
69+
}
70+
71+
private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e)
72+
{
73+
EntryAddedEventArgs propagated = new EntryAddedEventArgs();
74+
propagated.Entry = new LogEntry();
75+
propagated.Entry.Kind = e.Entry.Source.ToString();
76+
propagated.Entry.Message = e.Entry.Text;
77+
this.OnEntryAdded(propagated);
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)