After upgrading to
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.3.0</version>
</dependency>
I had to update code as shown below.
public class AppDriver extends TestListener_Error {
private static final ThreadLocal<AppiumDriver> driverThread = new ThreadLocal<>();
private static final Logger log = LogManager.getLogger();
public static String getCurrentContext() {
log.info("Entering");
return ((SupportsContextSwitching) driverThread).getContext();
}
public static Set getAllContexts() {
log.info("Entering");
return ((SupportsContextSwitching) driverThread).getContextHandles();
}
}
The following error is generated when getCurrentContext() is called. The error occurs for iOS only. When the same code is executed on an Android device, the ClassCastException error is not thrown. What could be the reason? How do I resolve this issue?
java.lang.ClassCastException: class java.lang.ThreadLocal cannot be cast to class io.appium.java_client.remote.SupportsContextSwitching (java.lang.ThreadLocal is in module java.base of loader 'bootstrap'; io.appium.java_client.remote.SupportsContextSwitching is in unnamed module of loader 'app')