Skip to content

Commit 5e66e77

Browse files
committed
fix error that can occur with JsonToBeanConverter and invalid selector exception due to multiple error status matches
Fixes #3117
1 parent 93f5a23 commit 5e66e77

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import java.util.HashMap;
5353
import java.util.HashSet;
54+
import java.util.List;
5455
import java.util.Map;
5556
import java.util.Optional;
5657
import java.util.Set;
@@ -127,15 +128,16 @@ public int toStatus(String webdriverState, Optional<Integer> httpStatus) {
127128
return 0;
128129
}
129130

130-
Set<KnownError> possibleMatches = KNOWN_ERRORS.stream()
131+
List<KnownError> possibleMatches = KNOWN_ERRORS.stream()
131132
.filter(knownError -> knownError.getW3cCode().equals(webdriverState))
132133
.filter(KnownError::isCanonicalForW3C)
133-
.collect(Collectors.toSet());
134+
.sorted((a,b) -> Integer.compare(a.getJsonCode(),b.getJsonCode()))
135+
.collect(Collectors.toList());
134136

135137
if (possibleMatches.isEmpty()) {
136138
return UNHANDLED_ERROR;
137139
}
138-
KnownError error = Iterables.getOnlyElement(possibleMatches);
140+
KnownError error = possibleMatches.get(0);
139141
if (httpStatus.isPresent() && httpStatus.get() != error.getW3cHttpStatus()) {
140142
log.info(String.format(
141143
"HTTP Status: '%d' -> incorrect JSON status mapping for '%s' (%d expected)",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ public void testShouldRecognizeStringStatus() {
404404
assertEquals("cheese", value);
405405
}
406406

407+
@Test
408+
public void testShouldConvertInvalidSelectorError() {
409+
Response response = new JsonToBeanConverter()
410+
.convert(Response.class, "{\"state\":\"invalid selector\",\"message\":\"invalid xpath selector\"}");
411+
assertEquals(32, response.getStatus().intValue());
412+
assertEquals(new ErrorCodes().toState(32), response.getState());
413+
}
414+
407415
@Test
408416
public void testShouldRecognizeStringState() {
409417
Response response = new JsonToBeanConverter()

0 commit comments

Comments
 (0)