Skip to content

Commit d895b6b

Browse files
Merge branch 'trunk' into webelement-nullable-2
2 parents c55eb00 + 2357514 commit d895b6b

File tree

5 files changed

+132
-6
lines changed

5 files changed

+132
-6
lines changed

java/src/org/openqa/selenium/grid/data/NodeStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static NodeStatus fromJson(JsonInput input) {
7676
Set<Slot> slots = null;
7777
Availability availability = null;
7878
Duration heartbeatPeriod = null;
79-
Duration sessionTimeout = null;
79+
Duration sessionTimeout = Duration.ofSeconds(300);
8080
String version = null;
8181
Map<String, String> osInfo = null;
8282

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,28 @@ public void close() {
511511
if (this.client == null) {
512512
return;
513513
}
514-
this.client = null;
514+
515515
for (WebSocket websocket : websockets) {
516516
try {
517517
websocket.close();
518518
} catch (Exception e) {
519519
LOG.log(Level.WARNING, "failed to close the websocket: " + websocket, e);
520520
}
521521
}
522-
executorService.shutdownNow();
522+
523+
if (this.client instanceof AutoCloseable) {
524+
AutoCloseable closeable = (AutoCloseable) this.client;
525+
executorService.submit(
526+
() -> {
527+
try {
528+
closeable.close();
529+
} catch (Exception e) {
530+
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
531+
}
532+
});
533+
}
534+
this.client = null;
535+
executorService.shutdown();
523536
}
524537

525538
@AutoService(HttpClient.Factory.class)

java/test/org/openqa/selenium/grid/data/NodeStatusTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,79 @@ void ensureRoundTripWorks() throws URISyntaxException {
7272

7373
assertThat(seen).isEqualTo(status);
7474
}
75+
76+
@Test
77+
void withoutSessionTimeoutInJsonStatus() throws URISyntaxException {
78+
String source =
79+
"{\n"
80+
+ " \"availability\": \"UP\",\n"
81+
+ " \"externalUri\": \"http:\\u002f\\u002f192.168.1.101:5555\",\n"
82+
+ " \"heartbeatPeriod\": 60000,\n"
83+
+ " \"maxSessions\": 1,\n"
84+
+ " \"nodeId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
85+
+ " \"osInfo\": {\n"
86+
+ " \"arch\": \"aarch64\",\n"
87+
+ " \"name\": \"Mac OS X\",\n"
88+
+ " \"version\": \"15.3\"\n"
89+
+ " },\n"
90+
+ " \"slots\": [\n"
91+
+ " {\n"
92+
+ " \"id\": {\n"
93+
+ " \"hostId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
94+
+ " \"id\": \"965e8cb4-7b48-4638-8bc8-6889c6319682\"\n"
95+
+ " },\n"
96+
+ " \"lastStarted\": \"1970-01-01T00:00:00Z\",\n"
97+
+ " \"session\": null,\n"
98+
+ " \"stereotype\": {\n"
99+
+ " \"browserName\": \"chrome\",\n"
100+
+ " \"platformName\": \"mac\"\n"
101+
+ " }\n"
102+
+ " }\n"
103+
+ " ],\n"
104+
+ " \"version\": \"4.17.0 (revision unknown*)\"\n"
105+
+ " }";
106+
107+
Json json = new Json();
108+
NodeStatus nodeStatus = json.toType(source, NodeStatus.class);
109+
110+
assertThat(nodeStatus.getSessionTimeout()).isEqualTo(Duration.ofSeconds(300));
111+
}
112+
113+
@Test
114+
void withSessionTimeoutInJsonStatus() throws URISyntaxException {
115+
String source =
116+
"{\n"
117+
+ " \"availability\": \"UP\",\n"
118+
+ " \"externalUri\": \"http:\\u002f\\u002f192.168.1.101:5555\",\n"
119+
+ " \"heartbeatPeriod\": 60000,\n"
120+
+ " \"maxSessions\": 1,\n"
121+
+ " \"sessionTimeout\": 600000,\n"
122+
+ " \"nodeId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
123+
+ " \"osInfo\": {\n"
124+
+ " \"arch\": \"aarch64\",\n"
125+
+ " \"name\": \"Mac OS X\",\n"
126+
+ " \"version\": \"15.3\"\n"
127+
+ " },\n"
128+
+ " \"slots\": [\n"
129+
+ " {\n"
130+
+ " \"id\": {\n"
131+
+ " \"hostId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
132+
+ " \"id\": \"965e8cb4-7b48-4638-8bc8-6889c6319682\"\n"
133+
+ " },\n"
134+
+ " \"lastStarted\": \"1970-01-01T00:00:00Z\",\n"
135+
+ " \"session\": null,\n"
136+
+ " \"stereotype\": {\n"
137+
+ " \"browserName\": \"chrome\",\n"
138+
+ " \"platformName\": \"mac\"\n"
139+
+ " }\n"
140+
+ " }\n"
141+
+ " ],\n"
142+
+ " \"version\": \"4.17.0 (revision unknown*)\"\n"
143+
+ " }";
144+
145+
Json json = new Json();
146+
NodeStatus nodeStatus = json.toType(source, NodeStatus.class);
147+
148+
assertThat(nodeStatus.getSessionTimeout()).isEqualTo(Duration.ofSeconds(600));
149+
}
75150
}

py/selenium/webdriver/remote/webdriver.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,24 +715,34 @@ def get_cookies(self) -> List[dict]:
715715
return self.execute(Command.GET_ALL_COOKIES)["value"]
716716

717717
def get_cookie(self, name) -> Optional[Dict]:
718-
"""Get a single cookie by name. Returns the cookie if found, None if
719-
not.
718+
"""Get a single cookie by name. Raises ValueError if the name is empty
719+
or whitespace. Returns the cookie if found, None if not.
720720
721721
Example:
722722
--------
723723
>>> cookie = driver.get_cookie('my_cookie')
724724
"""
725+
if not name or name.isspace():
726+
raise ValueError("Cookie name cannot be empty")
727+
725728
with contextlib.suppress(NoSuchCookieException):
726729
return self.execute(Command.GET_COOKIE, {"name": name})["value"]
730+
727731
return None
728732

729733
def delete_cookie(self, name) -> None:
730-
"""Deletes a single cookie with the given name.
734+
"""Deletes a single cookie with the given name. Raises ValueError if
735+
the name is empty or whitespace.
731736
732737
Example:
733738
--------
734739
>>> driver.delete_cookie('my_cookie')
735740
"""
741+
742+
# firefox deletes all cookies when "" is passed as name
743+
if not name or name.isspace():
744+
raise ValueError("Cookie name cannot be empty")
745+
736746
self.execute(Command.DELETE_COOKIE, {"name": name})
737747

738748
def delete_all_cookies(self) -> None:

py/test/selenium/webdriver/common/cookie_tests.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,31 @@ def test_should_not_delete_cookies_with_asimilar_name(cookie, driver, webserver)
152152
cookies = driver.get_cookies()
153153
assert cookie["name"] != cookies[0]["name"]
154154
assert cookie2["name"] == cookies[0]["name"]
155+
156+
157+
def test_get_cookie_raises_value_error_for_empty_name(cookie, driver):
158+
driver.add_cookie(cookie)
159+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
160+
driver.get_cookie("")
161+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
162+
driver.get_cookie(" ")
163+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
164+
driver.get_cookie(None)
165+
166+
167+
def test_delete_cookie_raises_value_error_for_empty_name(cookie, driver):
168+
cookie2 = cookie.copy()
169+
cookie2["name"] = "{}x".format(cookie["name"])
170+
driver.add_cookie(cookie)
171+
driver.add_cookie(cookie2)
172+
173+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
174+
driver.delete_cookie("")
175+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
176+
driver.get_cookie(" ")
177+
with pytest.raises(ValueError, match="Cookie name cannot be empty"):
178+
driver.get_cookie(None)
179+
180+
cookies = driver.get_cookies()
181+
182+
assert len(cookies) == 2

0 commit comments

Comments
 (0)