Skip to content

Commit 73cb988

Browse files
committed
Introduce NoSuchCookieException
1 parent 3c5ebb7 commit 73cb988

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

dotnet/src/webdriver/CookieJar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public Cookie GetCookieNamed(string name)
6666
{
6767
if (name is null)
6868
{
69-
throw new ArgumentNullException("{nameof(name)}");
69+
throw new ArgumentNullException(nameof(name));
7070
}
7171

72-
var rawCookie = driver.InternalExecute($"{DriverCommand.GetCookie}/{name}", null).Value;
72+
var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
7373

7474
return Cookie.FromDictionary(rawCookie as Dictionary<string, object>);
7575
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// <copyright file="NoSuchCookieException.cs" company="Selenium 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
7+
// "License"); you may not use this file except in compliance
8+
// with the License. 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,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
22+
#nullable enable
23+
24+
namespace OpenQA.Selenium
25+
{
26+
/// <summary>
27+
/// The exception that is thrown when a cookie is not found.
28+
/// </summary>
29+
[Serializable]
30+
public class NoSuchCookieException : NotFoundException
31+
{
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="NoSuchCookieException"/> class.
34+
/// </summary>
35+
public NoSuchCookieException()
36+
: base()
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="NoSuchCookieException"/> class with
42+
/// a specified error message.
43+
/// </summary>
44+
/// <param name="message">The message that describes the error.</param>
45+
public NoSuchCookieException(string? message)
46+
: base(message)
47+
{
48+
}
49+
50+
/// <summary>
51+
/// Initializes a new instance of the <see cref="NoSuchCookieException"/> class with
52+
/// a specified error message and a reference to the inner exception that is the
53+
/// cause of this exception.
54+
/// </summary>
55+
/// <param name="message">The error message that explains the reason for the exception.</param>
56+
/// <param name="innerException">The exception that is the cause of the current exception,
57+
/// or <see langword="null"/> if no inner exception is specified.</param>
58+
public NoSuchCookieException(string? message, Exception? innerException)
59+
: base(message, innerException)
60+
{
61+
}
62+
}
63+
}

dotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected override void InitializeCommandDictionary()
108108
this.TryAddCommand(DriverCommand.ExecuteScript, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/execute/sync"));
109109
this.TryAddCommand(DriverCommand.ExecuteAsyncScript, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/execute/async"));
110110
this.TryAddCommand(DriverCommand.GetAllCookies, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/cookie"));
111-
this.TryAddCommand(DriverCommand.GetCookie, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/cookie/{name}"));
111+
this.TryAddCommand(DriverCommand.GetCookie, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/cookie/{name}"));
112112
this.TryAddCommand(DriverCommand.AddCookie, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/cookie"));
113113
this.TryAddCommand(DriverCommand.DeleteCookie, new HttpCommandInfo(HttpCommandInfo.DeleteCommand, "/session/{sessionId}/cookie/{name}"));
114114
this.TryAddCommand(DriverCommand.DeleteAllCookies, new HttpCommandInfo(HttpCommandInfo.DeleteCommand, "/session/{sessionId}/cookie"));

dotnet/src/webdriver/WebDriver.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command
853853
case WebDriverResult.InsecureCertificate:
854854
throw new InsecureCertificateException(errorMessage);
855855

856+
case WebDriverResult.NoSuchCookie:
857+
throw new NoSuchCookieException(errorMessage);
858+
856859
default:
857860
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", errorMessage, errorResponse.Status));
858861
}

0 commit comments

Comments
 (0)