Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ public void addCookie(Cookie cookie) {

@Override
public void deleteCookieNamed(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Cookie name cannot be empty");
}
execute(DriverCommand.DELETE_COOKIE(name));
}

Expand Down Expand Up @@ -927,6 +930,9 @@ public Set<Cookie> getCookies() {

@Override
public Cookie getCookieNamed(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Cookie name cannot be empty");
}
Set<Cookie> allCookies = getCookies();
for (Cookie cookie : allCookies) {
if (cookie.getName().equals(name)) {
Expand Down
13 changes: 13 additions & 0 deletions java/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.openqa.selenium.testing.drivers.Browser.ALL;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
Expand Down Expand Up @@ -503,6 +504,18 @@ public void testDeleteNotExistedCookie() {
driver.manage().deleteCookieNamed(key);
}

@Test
public void testDeleteEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" "));
}

@Test
public void testGetEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" "));
}

@Test
@Ignore(value = ALL, reason = "Non W3C conformant")
public void testShouldDeleteOneOfTheCookiesWithTheSameName() {
Expand Down
Loading