diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs
index 0f2695b96a2de..470d81653cdff 100644
--- a/dotnet/src/webdriver/CookieJar.cs
+++ b/dotnet/src/webdriver/CookieJar.cs
@@ -74,16 +74,16 @@ public void AddCookie(Cookie cookie)
/// Delete the cookie by passing in the name of the cookie
///
/// The name of the cookie that is in the browser
- /// If is .
+ /// If is or .
public void DeleteCookieNamed(string name)
{
- if (name is null)
+ if (string.IsNullOrWhiteSpace(name))
{
- throw new ArgumentNullException(nameof(name));
+ throw new ArgumentException("Cookie name cannot be null or empty", nameof(name));
}
- Dictionary parameters = new Dictionary();
- parameters.Add("name", name);
+ Dictionary parameters = new() { { "name", name } };
+
driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
}
@@ -115,11 +115,12 @@ public void DeleteAllCookies()
///
/// name of the cookie that needs to be returned
/// A Cookie from the name; or if not found.
+ /// If is or .
public Cookie? GetCookieNamed(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
- throw new ArgumentException("Cookie name cannot be empty", nameof(name));
+ throw new ArgumentException("Cookie name cannot be null or empty", nameof(name));
}
try
diff --git a/dotnet/src/webdriver/ICookieJar.cs b/dotnet/src/webdriver/ICookieJar.cs
index f9eb69a4824bc..b73a3085c6aba 100644
--- a/dotnet/src/webdriver/ICookieJar.cs
+++ b/dotnet/src/webdriver/ICookieJar.cs
@@ -61,7 +61,7 @@ public interface ICookieJar
/// Deletes the cookie with the specified name from the page.
///
/// The name of the cookie to be deleted.
- /// If is .
+ /// If is or .
void DeleteCookieNamed(string name);
///
diff --git a/dotnet/test/common/CookieImplementationTest.cs b/dotnet/test/common/CookieImplementationTest.cs
index a329895d79b7d..2cc8a3c5cc2e8 100644
--- a/dotnet/test/common/CookieImplementationTest.cs
+++ b/dotnet/test/common/CookieImplementationTest.cs
@@ -620,6 +620,28 @@ public void DeleteAllCookiesDifferentUrls()
AssertCookieIsPresentWithName(cookie2.Name);
}
+ [Test]
+ [TestCase(null)]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void ShouldThrowWhenGetInvalidCookieByName(string cookieName)
+ {
+ var getCookieAction = () => driver.Manage().Cookies.GetCookieNamed(cookieName);
+
+ Assert.That(getCookieAction, Throws.ArgumentException);
+ }
+
+ [Test]
+ [TestCase(null)]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void ShouldThrowWhenDeleteInvalidCookieByName(string cookieName)
+ {
+ var deleteCookieAction = () => driver.Manage().Cookies.DeleteCookieNamed(cookieName);
+
+ Assert.That(deleteCookieAction, Throws.ArgumentException);
+ }
+
//------------------------------------------------------------------
// Tests below here are not included in the Java test suite
//------------------------------------------------------------------