When trying to get context handles in iOS, throws an exception

When trying to get context handles in iOS, throws an exception.

java.lang.ClassCastException: class com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to class java.lang.String (com.google.common.collect.Maps$TransformedEntriesMap is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

Steps I m trying to achieve

  1. Open the app and perform some operations
  2. Then switch to Safari browser and perform operations

Below is the sample code snippet

((IOSDriver)driver).activateApp("com.apple.mobilesafari");
Set<String> contexts = ((IOSDriver) driver).getContextHandles();
for(String handle:contexts)
{
    System.out.println(handle);
}

I have also added capabilities related to webview as well

        capabilities.setCapability("fullContextList", true);
        capabilities.setCapability("includeSafariInWebviews","true");

Appium java client version 8.0.0
Appium version 1.22.0

I think you are running into a bug in java-client:

I assume this is expected with strict typing. Try to use https://github.com/appium/appium-xcuitest-driver#mobile-getcontexts instead to fetch extended contexts info

1 Like

in one of the comments, it says

In v2.0 this code has been moved to a separate plugin and the recent version of it should have the fix

Where can I find this plugin?

I don’t know what plugin/where it is, but perhaps you should direct your question to the commenter, who happens to be a commenter in this thread too.

1 Like

Removing this capability will solve it:

You’ll get a plain string without this. This capability will include more information for each context.