Skip to content

Commit 20d0f65

Browse files
committed
Updating version-independent CDP API for .NET
1 parent 4eeb13e commit 20d0f65

7 files changed

Lines changed: 70 additions & 28 deletions

File tree

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public object ExecuteChromeCommandWithResult(string commandName, Dictionary<stri
168168
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
169169
/// </summary>
170170
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
171-
public IDevToolsSession CreateDevToolsSession()
171+
public DevToolsSession CreateDevToolsSession()
172172
{
173173
if (!this.Capabilities.HasCapability(this.optionsCapabilityName))
174174
{

dotnet/src/webdriver/DevTools/HttpResponseData.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace OpenQA.Selenium.DevTools
2727
/// </summary>
2828
public class HttpResponseData
2929
{
30+
private Dictionary<string, string> headers = new Dictionary<string, string>();
31+
3032
/// <summary>
3133
/// The numeric status code of the HTTP response.
3234
/// </summary>
@@ -40,6 +42,6 @@ public class HttpResponseData
4042
/// <summary>
4143
/// The headers of the HTTP response.
4244
/// </summary>
43-
public Dictionary<string, string> Headers { get; set; }
45+
public Dictionary<string, string> Headers => this.headers;
4446
}
4547
}

dotnet/src/webdriver/DevTools/IDevTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public interface IDevTools
2727
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
2828
/// </summary>
2929
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
30-
IDevToolsSession CreateDevToolsSession();
30+
DevToolsSession CreateDevToolsSession();
3131
}
3232
}

dotnet/src/webdriver/DevTools/Network.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public abstract class Network
4848
/// <returns>A task that represents the asynchronous operation.</returns>
4949
public abstract Task EnableNetworkCaching();
5050

51+
public abstract Task EnableNetwork();
52+
53+
public abstract Task DisableNetwork();
54+
5155
/// <summary>
5256
/// Asynchronously enables the fetch domain for all URL patterns.
5357
/// </summary>
@@ -78,18 +82,18 @@ public abstract class Network
7882
/// <summary>
7983
/// Asynchronously continues an intercepted network call using authentication.
8084
/// </summary>
81-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
85+
/// <param name="requestId">The ID of the network request for which to continue with authentication.</param>
8286
/// <param name="userName">The user name with which to authenticate.</param>
8387
/// <param name="password">The password with which to authenticate.</param>
8488
/// <returns>A task that represents the asynchronous operation.</returns>
85-
public abstract Task ContinueWithAuth(HttpRequestData requestData, string userName, string password);
89+
public abstract Task ContinueWithAuth(string requestId, string userName, string password);
8690

8791
/// <summary>
8892
/// Asynchronously cancels authorization of an intercepted network request.
8993
/// </summary>
90-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
94+
/// <param name="requestId">The ID of the network request for which to cancel authentication.</param>
9195
/// <returns>A task that represents the asynchronous operation.</returns>
92-
public abstract Task CancelAuth(HttpRequestData requestData);
96+
public abstract Task CancelAuth(string requestId);
9397

9498
/// <summary>
9599
/// Raises the AuthRequired event.

dotnet/src/webdriver/DevTools/v84/V84Network.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Text;
2122
using System.Threading.Tasks;
2223
using OpenQA.Selenium.DevTools.V84.Fetch;
2324
using OpenQA.Selenium.DevTools.V84.Network;
@@ -63,6 +64,16 @@ public override async Task EnableNetworkCaching()
6364
await network.SetCacheDisabled(new SetCacheDisabledCommandSettings() { CacheDisabled = false });
6465
}
6566

67+
public override async Task EnableNetwork()
68+
{
69+
await network.Enable(new Network.EnableCommandSettings());
70+
}
71+
72+
public override async Task DisableNetwork()
73+
{
74+
await network.Disable();
75+
}
76+
6677
/// <summary>
6778
/// Asynchronously enables the fetch domain for all URL patterns.
6879
/// </summary>
@@ -115,8 +126,7 @@ public override async Task ContinueRequest(HttpRequestData requestData, HttpResp
115126

116127
if (!string.IsNullOrEmpty(responseData.Body))
117128
{
118-
// TODO: base64 encode?
119-
commandSettings.Body = responseData.Body;
129+
commandSettings.Body = Convert.ToBase64String(Encoding.UTF8.GetBytes(responseData.Body));
120130
}
121131

122132
await fetch.FulfillRequest(commandSettings);
@@ -135,14 +145,15 @@ public override async Task ContinueWithoutModification(HttpRequestData requestDa
135145
/// <summary>
136146
/// Asynchronously continues an intercepted network call using authentication.
137147
/// </summary>
138-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
148+
/// <param name="requestId">The ID of the network request for which to continue with authentication.</param>
139149
/// <param name="userName">The user name with which to authenticate.</param>
140150
/// <param name="password">The password with which to authenticate.</param>
141151
/// <returns>A task that represents the asynchronous operation.</returns>
142-
public override async Task ContinueWithAuth(HttpRequestData requestData, string userName, string password)
152+
public override async Task ContinueWithAuth(string requestId, string userName, string password)
143153
{
144154
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
145155
{
156+
RequestId = requestId,
146157
AuthChallengeResponse = new OpenQA.Selenium.DevTools.V84.Fetch.AuthChallengeResponse()
147158
{
148159
Response = OpenQA.Selenium.DevTools.V84.Fetch.AuthChallengeResponseResponseValues.ProvideCredentials,
@@ -155,12 +166,13 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
155166
/// <summary>
156167
/// Asynchronously cancels authorization of an intercepted network request.
157168
/// </summary>
158-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
169+
/// <param name="requestId">The ID of the network request for which to cancel authentication.</param>
159170
/// <returns>A task that represents the asynchronous operation.</returns>
160-
public override async Task CancelAuth(HttpRequestData requestData)
171+
public override async Task CancelAuth(string requestId)
161172
{
162173
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
163174
{
175+
RequestId = requestId,
164176
AuthChallengeResponse = new OpenQA.Selenium.DevTools.V84.Fetch.AuthChallengeResponse()
165177
{
166178
Response = OpenQA.Selenium.DevTools.V84.Fetch.AuthChallengeResponseResponseValues.CancelAuth
@@ -173,7 +185,7 @@ private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e)
173185
AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs()
174186
{
175187
RequestId = e.RequestId,
176-
Uri = e.AuthChallenge.Origin
188+
Uri = e.Request.Url
177189
};
178190

179191
this.OnAuthRequired(wrapped);

dotnet/src/webdriver/DevTools/v85/V85Network.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Text;
2122
using System.Threading.Tasks;
2223
using OpenQA.Selenium.DevTools.V85.Fetch;
2324
using OpenQA.Selenium.DevTools.V85.Network;
@@ -63,6 +64,16 @@ public override async Task EnableNetworkCaching()
6364
await network.SetCacheDisabled(new SetCacheDisabledCommandSettings() { CacheDisabled = false });
6465
}
6566

67+
public override async Task EnableNetwork()
68+
{
69+
await network.Enable(new Network.EnableCommandSettings());
70+
}
71+
72+
public override async Task DisableNetwork()
73+
{
74+
await network.Disable();
75+
}
76+
6677
/// <summary>
6778
/// Asynchronously enables the fetch domain for all URL patterns.
6879
/// </summary>
@@ -115,8 +126,7 @@ public override async Task ContinueRequest(HttpRequestData requestData, HttpResp
115126

116127
if (!string.IsNullOrEmpty(responseData.Body))
117128
{
118-
// TODO: base64 encode?
119-
commandSettings.Body = responseData.Body;
129+
commandSettings.Body = Convert.ToBase64String(Encoding.UTF8.GetBytes(responseData.Body));
120130
}
121131

122132
await fetch.FulfillRequest(commandSettings);
@@ -135,14 +145,15 @@ public override async Task ContinueWithoutModification(HttpRequestData requestDa
135145
/// <summary>
136146
/// Asynchronously continues an intercepted network call using authentication.
137147
/// </summary>
138-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
148+
/// <param name="requestId">The ID of the network request for which to continue with authentication.</param>
139149
/// <param name="userName">The user name with which to authenticate.</param>
140150
/// <param name="password">The password with which to authenticate.</param>
141151
/// <returns>A task that represents the asynchronous operation.</returns>
142-
public override async Task ContinueWithAuth(HttpRequestData requestData, string userName, string password)
152+
public override async Task ContinueWithAuth(string requestId, string userName, string password)
143153
{
144154
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
145155
{
156+
RequestId = requestId,
146157
AuthChallengeResponse = new OpenQA.Selenium.DevTools.V85.Fetch.AuthChallengeResponse()
147158
{
148159
Response = OpenQA.Selenium.DevTools.V85.Fetch.AuthChallengeResponseResponseValues.ProvideCredentials,
@@ -155,12 +166,13 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
155166
/// <summary>
156167
/// Asynchronously cancels authorization of an intercepted network request.
157168
/// </summary>
158-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
169+
/// <param name="requestId">The ID of the network request for which to cancel authentication.</param>
159170
/// <returns>A task that represents the asynchronous operation.</returns>
160-
public override async Task CancelAuth(HttpRequestData requestData)
171+
public override async Task CancelAuth(string requestId)
161172
{
162173
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
163174
{
175+
RequestId = requestId,
164176
AuthChallengeResponse = new OpenQA.Selenium.DevTools.V85.Fetch.AuthChallengeResponse()
165177
{
166178
Response = OpenQA.Selenium.DevTools.V85.Fetch.AuthChallengeResponseResponseValues.CancelAuth
@@ -173,7 +185,7 @@ private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e)
173185
AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs()
174186
{
175187
RequestId = e.RequestId,
176-
Uri = e.AuthChallenge.Origin
188+
Uri = e.Request.Url
177189
};
178190

179191
this.OnAuthRequired(wrapped);

dotnet/src/webdriver/DevTools/v86/V86Network.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Text;
2122
using System.Threading.Tasks;
2223
using OpenQA.Selenium.DevTools.V86.Fetch;
2324
using OpenQA.Selenium.DevTools.V86.Network;
@@ -63,6 +64,16 @@ public override async Task EnableNetworkCaching()
6364
await network.SetCacheDisabled(new SetCacheDisabledCommandSettings() { CacheDisabled = false });
6465
}
6566

67+
public override async Task EnableNetwork()
68+
{
69+
await network.Enable(new Network.EnableCommandSettings());
70+
}
71+
72+
public override async Task DisableNetwork()
73+
{
74+
await network.Disable();
75+
}
76+
6677
/// <summary>
6778
/// Asynchronously enables the fetch domain for all URL patterns.
6879
/// </summary>
@@ -115,8 +126,7 @@ public override async Task ContinueRequest(HttpRequestData requestData, HttpResp
115126

116127
if (!string.IsNullOrEmpty(responseData.Body))
117128
{
118-
// TODO: base64 encode?
119-
commandSettings.Body = responseData.Body;
129+
commandSettings.Body = Convert.ToBase64String(Encoding.UTF8.GetBytes(responseData.Body));
120130
}
121131

122132
await fetch.FulfillRequest(commandSettings);
@@ -135,14 +145,15 @@ public override async Task ContinueWithoutModification(HttpRequestData requestDa
135145
/// <summary>
136146
/// Asynchronously continues an intercepted network call using authentication.
137147
/// </summary>
138-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
148+
/// <param name="requestId">The ID of the network request for which to continue with authentication.</param>
139149
/// <param name="userName">The user name with which to authenticate.</param>
140150
/// <param name="password">The password with which to authenticate.</param>
141151
/// <returns>A task that represents the asynchronous operation.</returns>
142-
public override async Task ContinueWithAuth(HttpRequestData requestData, string userName, string password)
152+
public override async Task ContinueWithAuth(string requestId, string userName, string password)
143153
{
144154
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
145155
{
156+
RequestId = requestId,
146157
AuthChallengeResponse = new V86.Fetch.AuthChallengeResponse()
147158
{
148159
Response = V86.Fetch.AuthChallengeResponseResponseValues.ProvideCredentials,
@@ -155,12 +166,13 @@ await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
155166
/// <summary>
156167
/// Asynchronously cancels authorization of an intercepted network request.
157168
/// </summary>
158-
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
169+
/// <param name="requestId">The ID of the network request for which to cancel authentication.</param>
159170
/// <returns>A task that represents the asynchronous operation.</returns>
160-
public override async Task CancelAuth(HttpRequestData requestData)
171+
public override async Task CancelAuth(string requestId)
161172
{
162173
await fetch.ContinueWithAuth(new ContinueWithAuthCommandSettings()
163174
{
175+
RequestId = requestId,
164176
AuthChallengeResponse = new OpenQA.Selenium.DevTools.V86.Fetch.AuthChallengeResponse()
165177
{
166178
Response = V86.Fetch.AuthChallengeResponseResponseValues.CancelAuth
@@ -173,7 +185,7 @@ private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e)
173185
AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs()
174186
{
175187
RequestId = e.RequestId,
176-
Uri = e.AuthChallenge.Origin
188+
Uri = e.Request.Url
177189
};
178190

179191
this.OnAuthRequired(wrapped);

0 commit comments

Comments
 (0)