Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 11 additions & 9 deletions src/main/java/io/appium/java_client/ErrorCodesMobile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package io.appium.java_client;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.ErrorCodes;

Expand All @@ -27,7 +28,7 @@
*
* @author jonahss@gmail.com (Jonah Stiennon)
*/
public class ErrorCodesMobile extends ErrorCodes {

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 25 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 25 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 25 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 25 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 25 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 17 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 17 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 17 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 17 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 17 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / JDK 21 build (stable)

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest flutter-android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest flutter-android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest flutter-android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest flutter-android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - ubuntu-latest flutter-android

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 flutter-ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 flutter-ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 flutter-ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 flutter-ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

Check warning on line 31 in src/main/java/io/appium/java_client/ErrorCodesMobile.java

View workflow job for this annotation

GitHub Actions / e2e - macos-15 flutter-ios

[removal] ErrorCodes in org.openqa.selenium.remote has been deprecated and marked for removal

public static final int NO_SUCH_CONTEXT = 35;

Expand All @@ -51,21 +52,22 @@
}

/**
* Returns the exception type that corresponds to the given {@code message}or {@code null} if
* there are no matching mobile exceptions.
* Returns the exception type that corresponds to the given {@code message}. Messages that do not
* match a mobile exception are resolved by the standard W3C error mapping.
*
* @param message message An error message returned by Appium server
* @return The exception type that corresponds to the provided error message or {@code null} if
* there are no matching mobile exceptions.
* @return The exception type that corresponds to the provided error message.
*/
@Override
public Class<? extends WebDriverException> getExceptionType(String message) {
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
if (message.contains(entry.getValue())) {
return getExceptionType(entry.getKey());
public Class<? extends WebDriverException> getExceptionType(@Nullable String message) {
if (message != null) {
for (Map.Entry<Integer, String> entry : statusToState.entrySet()) {
if (message.contains(entry.getValue())) {
return getExceptionType(entry.getKey());
}
}
}
return null;
return super.getExceptionType(message);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/io/appium/java_client/ErrorCodesMobileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.appium.java_client;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriverException;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ErrorCodesMobileTest {
private final ErrorCodesMobile errorCodes = new ErrorCodesMobile();

@Test
void resolvesMobileExceptionFromMessage() {
assertEquals(NoSuchContextException.class, errorCodes.getExceptionType("No such context found"));
}

@Test
void resolvesStandardExceptionsFromW3cState() {
assertEquals(NoSuchElementException.class, errorCodes.getExceptionType("no such element"));
assertEquals(StaleElementReferenceException.class,
errorCodes.getExceptionType("stale element reference"));
}

@Test
void resolvesUnknownOrMissingStateToWebDriverException() {
assertEquals(WebDriverException.class, errorCodes.getExceptionType("not a real error"));
assertEquals(WebDriverException.class, errorCodes.getExceptionType((String) null));
}
}
Loading