Skip to content

Commit de8579b

Browse files
committed
Adding support for CDP version 87 in .NET
1 parent be6f8ee commit de8579b

13 files changed

+711
-2
lines changed

dotnet/src/webdriver/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ generated_assembly_info(
5151
"//dotnet/src/webdriver/cdp:generate-v84",
5252
"//dotnet/src/webdriver/cdp:generate-v85",
5353
"//dotnet/src/webdriver/cdp:generate-v86",
54+
"//dotnet/src/webdriver/cdp:generate-v87",
5455
],
5556
out = "WebDriver",
5657
resources = [
@@ -99,6 +100,7 @@ generated_assembly_info(
99100
"//dotnet/src/webdriver/cdp:generate-v84",
100101
"//dotnet/src/webdriver/cdp:generate-v85",
101102
"//dotnet/src/webdriver/cdp:generate-v86",
103+
"//dotnet/src/webdriver/cdp:generate-v87",
102104
],
103105
out = "WebDriver",
104106
resources = [
@@ -138,6 +140,7 @@ generated_assembly_info(
138140
"//dotnet/src/webdriver/cdp:generate-v84",
139141
"//dotnet/src/webdriver/cdp:generate-v85",
140142
"//dotnet/src/webdriver/cdp:generate-v86",
143+
"//dotnet/src/webdriver/cdp:generate-v87",
141144
],
142145
out = "strongnamed/WebDriver",
143146
keyfile = "//dotnet:WebDriver.snk",
@@ -187,6 +190,7 @@ generated_assembly_info(
187190
"//dotnet/src/webdriver/cdp:generate-v84",
188191
"//dotnet/src/webdriver/cdp:generate-v85",
189192
"//dotnet/src/webdriver/cdp:generate-v86",
193+
"//dotnet/src/webdriver/cdp:generate-v87",
190194
],
191195
out = "strongnamed/WebDriver",
192196
keyfile = "//dotnet:WebDriver.snk",

dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public abstract class DevToolsDomains
3434
// This is the list of known supported DevTools version implementation.
3535
// Note carefully that it is sorted in reverse order, most recent
3636
// version first, as that is more likely to match. When new versions
37-
// are implemented for support,
37+
// are implemented for support, new types must be added to this list.
3838
private static readonly List<Type> SupportedDevToolsVersions = new List<Type>()
3939
{
40+
typeof(V87.V87Domains),
4041
typeof(V86.V86Domains),
4142
typeof(V85.V85Domains),
4243
typeof(V84.V84Domains)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// <copyright file="V86Domains.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.V87
23+
{
24+
/// <summary>
25+
/// Class containing the domain implementation for version 86 of the DevTools Protocol.
26+
/// </summary>
27+
public class V87Domains : DevToolsDomains
28+
{
29+
private DevToolsSessionDomains domains;
30+
31+
public V87Domains(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 => 87;
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 V87Network(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 V87JavaScript(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 V87Target(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 V87Log(domains.Log);
65+
}
66+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// <copyright file="V86JavaScript.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.V87.Page;
22+
using OpenQA.Selenium.DevTools.V87.Runtime;
23+
24+
namespace OpenQA.Selenium.DevTools.V87
25+
{
26+
/// <summary>
27+
/// Class containing the JavaScript implementation for version 85 of the DevTools Protocol.
28+
/// </summary>
29+
public class V87JavaScript : JavaScript
30+
{
31+
private RuntimeAdapter runtime;
32+
private PageAdapter page;
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="V86JavaScript"/> 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 V87JavaScript(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+
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
126+
{
127+
BindingCalledEventArgs wrapped = new BindingCalledEventArgs()
128+
{
129+
ExecutionContextId = e.ExecutionContextId,
130+
Name = e.Name,
131+
Payload = e.Payload
132+
};
133+
134+
this.OnBindingCalled(wrapped);
135+
}
136+
137+
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
138+
{
139+
// TODO: Collect stack trace elements
140+
var wrapped = new ExceptionThrownEventArgs()
141+
{
142+
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
143+
Message = e.ExceptionDetails.Text
144+
};
145+
146+
this.OnExceptionThrown(wrapped);
147+
}
148+
149+
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
150+
{
151+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
152+
foreach (var arg in e.Args)
153+
{
154+
string argValue = null;
155+
if (arg.Value != null)
156+
{
157+
argValue = arg.Value.ToString();
158+
}
159+
args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue });
160+
}
161+
162+
var wrapped = new ConsoleApiCalledEventArgs()
163+
{
164+
Timestamp = new DateTime(1979, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
165+
Type = e.Type,
166+
Arguments = args.AsReadOnly()
167+
};
168+
169+
this.OnConsoleApiCalled(wrapped);
170+
}
171+
}
172+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// <copyright file="V85Log.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.V87.Log;
24+
25+
namespace OpenQA.Selenium.DevTools.V87
26+
{
27+
/// <summary>
28+
/// Class containing the browser's log as referenced by version 86 of the DevTools Protocol.
29+
/// </summary>
30+
public class V87Log : DevTools.Log
31+
{
32+
private LogAdapter adapter;
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="V86Log"/> class.
36+
/// </summary>
37+
/// <param name="adapter">The adapter for the Log domain.</param>
38+
public V87Log(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)