java-client: java.lang.ClassCastException: class org.openqa.selenium.Platform$23 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$23 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

Description

Unable to create both IOSDriver and AndroidDriver after upgrading Selenium to 4.2.0 and Appium to 8.1.0. Error message displayed below:

Where creating iOSDriver:

java.lang.ClassCastException: class org.openqa.selenium.Platform$23 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$23 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

	at io.appium.java_client.AppiumDriver.ensurePlatformName(AppiumDriver.java:136)
	at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:105)

When creating AndroidDriver:

java.lang.ClassCastException: class org.openqa.selenium.Platform$22 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$22 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

	at io.appium.java_client.AppiumDriver.ensurePlatformName(AppiumDriver.java:136)
	at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)

Notes

  • iOSDriver created with Xcuitestoptions
  • AndroidDriver created with both DesiredCapabilities and UiAutomator2Options
  • Both methods results in the same cannot cast error message above

Environment

  • Java client build version or git revision if you use some snapshot: 8.1.0
  • Appium server version or git revision if you use some snapshot: 2.0.0-beta.24
  • Desktop OS/version used to run Appium if necessary: MacOS Monterey
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe:
  • Mobile platform/version under test: iOS/Android
  • Real device or emulator/simulator: emulator/simulator

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I was getting this issue on my Linux machine but not on my local Mac machine. We use Jenkins with Linux slaves pointing to Saucelabs.

The work around was to change from: caps.setCapability(“platformName”, platform); to: caps.setCapability(“appium:platformName”, platform);

It works with no issues so far.

Thanks for the update @n00bstr I’ve created another patch to fix the issue related to platformVersion capability. It turns out Selenium lib tries to add workarounds to browser issues, which badly hits our client: https://github.com/SeleniumHQ/selenium/blob/b0057b54cff7991add4299d58de53245f9d9ecf9/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java#L45

I will see how we can publish nightly or weekly builds, and then we can work on using them to check potential issues with the Appium client.

@SrinivasanTarget @mykola-mokhnach can you please release a patch version for appium? I can’t run any test due to this error… thanks!!!

That makes sense. Do you know how I can find all “implicit” dependencies between those two code bases? We’d like to be aware of how changes upstream affect this client.

Thanks @mykola-mokhnach , Platform issue has been resolved now.

I have updated java-client to 8.1.1 version , selenium-java to 4.2.1 and uiautomator2 to 2.2.0

Great tip, @SrinivasanTarget , tried that and have some progress. Please see below:

  • Android with DesiredCapabilities works
  • Android with UiAutomator2Options, unable to start a new session as there’s no vendor prefix (assuming it is the appium: prefix here)
  • iOS with XCUITestOptions, unable to start a new session as there’s no vendor prefix
  • iOS with Desired Capabilities works

@mykola-mokhnach Can you please see the above?

I guess the workaround here is to use DesiredCapabilities instead of the driver-specific XCUITestOptions and UiAutomator2Options for now.

Looks like the following commit in Selenium from 2 days ago is the cause of the issue: https://github.com/SeleniumHQ/selenium/commit/3f794a036ca9e1d63512dc8eb09aeacf016b9540 In SharedCapabilitiesMethods they’re now explicitly changing the type of the platformName capability from String to a Platform object, hence the objects mismatch.

I believe @mykola-mokhnach’s PR resolves the issue, however I don’t have a quick way to verify it at this time.