Skip to content

Commit 3e9fb10

Browse files
committed
Throw on non-List responses to the /log command.
W3C drivers that don't implement the Get Logs command will return an error object rather than a list.
1 parent 1103cb7 commit 3e9fb10

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

java/client/src/org/openqa/selenium/remote/RemoteLogs.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.common.collect.Lists;
2424

2525
import org.openqa.selenium.Beta;
26+
import org.openqa.selenium.UnsupportedCommandException;
2627
import org.openqa.selenium.WebDriverException;
2728
import org.openqa.selenium.logging.LocalLogs;
2829
import org.openqa.selenium.logging.LogCombiner;
@@ -79,6 +80,9 @@ public LogEntries get(String logType) {
7980

8081
private LogEntries getRemoteEntries(String logType) {
8182
Object raw = executeMethod.execute(DriverCommand.GET_LOG, ImmutableMap.of(TYPE_KEY, logType));
83+
if (!(raw instanceof List)) {
84+
throw new UnsupportedCommandException("malformed response to remote logs command");
85+
}
8286
@SuppressWarnings("unchecked")
8387
List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw;
8488
List<LogEntry> remoteEntries = Lists.newArrayListWithCapacity(rawList.size());

java/client/test/org/openqa/selenium/remote/RemoteLogsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.remote;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.fail;
2122
import static org.mockito.Mockito.verifyNoMoreInteractions;
2223
import static org.mockito.Mockito.when;
2324

@@ -125,6 +126,24 @@ public void canGetServerLogs() {
125126
verifyNoMoreInteractions(localLogs);
126127
}
127128

129+
@Test
130+
public void throwsOnBogusRemoteLogsResponse() {
131+
when(
132+
executeMethod
133+
.execute(DriverCommand.GET_LOG, ImmutableMap.of(RemoteLogs.TYPE_KEY, LogType.BROWSER)))
134+
.thenReturn(new ImmutableMap.Builder()
135+
.put("error", "unknown method")
136+
.put("message", "Command not found: POST /session/11037/log")
137+
.put("stacktrace", "").build());
138+
try {
139+
remoteLogs.get(LogType.BROWSER);
140+
fail("Should have thrown WebDriverException");
141+
} catch (WebDriverException expected) {
142+
}
143+
144+
verifyNoMoreInteractions(localLogs);
145+
}
146+
128147
@Test
129148
public void canGetAvailableLogTypes() {
130149
List<String> remoteAvailableLogTypes = new ArrayList<>();

0 commit comments

Comments
 (0)