Unable to initialize driver using appium-java 8

Hi everyone, I’m trying to test the appium v8.0.0 but cannot initialize the driver correctly.
Env:
Java 11
appium server: 1.21.0
appium client: 8.0.0

my pom:

4.0.0

<groupId>org.example</groupId>
<artifactId>mobile-test-example</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <appium.version>8.0.0</appium.version>
    <testng.version>7.4.0</testng.version>

</properties>
<dependencies>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>${testng.version}</version>
    <scope>test</scope>
</dependency>

    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>${appium.version}</version>
    </dependency>
</dependencies>

My test code:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“platformName”, Platform.ANDROID);
capabilities.setCapability(“deviceName”, “emulator-5556”);
capabilities.setCapability(“automationName”, “UIAutomator2”);
capabilities.setCapability(“app”, “/Users/test/Projects/mobile-test-example/build/wordpress.apk”);
capabilities.setCapability(“appPackage”, “org.wordpress.android”);
capabilities.setCapability(“appActivity”, “org.wordpress.android.ui.WPLaunchActivity”);

        final String URL_STRING = "http://127.0.0.1:4723/";
        URL url = new URL(URL_STRING);

        AndroidDriver driver = new AndroidDriver(url, capabilities);
        driver.findElement(By.id("org.wordpress.android:id/nux_username")).sendKeys("[email protected]");

The error return as:

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’)

I tried both AppiumDriver and AndroidDriver type but neither worked to me.

try add

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.1</version>
        </dependency>

change it to Platform.ANDROID.name().

In general, don’t use the Capabilities class at all, but the …Options one instead: java-client/docs/v7-to-v8-migration-guide.md at master · appium/java-client · GitHub

aaa. other solution move to:

MobilePlatform.ANDROID // this is Appium thing from 'package io.appium.java_client.remote;'

Thanks, got it works now.

Can anyone guide me how did it work? I am facing the same issue and at the same point. I am confuse how to migrate my code to javaclient8 because I am at very beginning of the automation. Anyone can help? Thanks in advance

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class AppiumCapabilities {
@Test
public void testAppium() throws MalformedURLException{

AndroidDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability("platformName", "Android");
capability.setCapability("deviceName", "Nexus 5");
capability.setCapability("platformVersion", "6.0.1");
capability.setCapability("udid","039e8ae813aa787d");

File file = new File("C:\\Users\\ShahreenMushtaq\\workspace1\\Appium\\zameenapk\\app-zameen-live-release.apk");
capability.setCapability("app", file.getAbsolutePath());

driver = new AndroidDriver(new URL("http://192.168.100.7:4723/wd/hub"),capability);

}
}

I have same problem with Initialize IOS driver in Appium 1.22.3

import com.codeborne.selenide.WebDriverProvider;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.net.MalformedURLException;
import java.net.URL;

@ParametersAreNonnullByDefault
public class iOSDriverProvider implements WebDriverProvider {
    @Override
    @CheckReturnValue
    @Nonnull
    public WebDriver createDriver(Capabilities capabilities) {

        XCUITestOptions options = new XCUITestOptions();
        options.merge(capabilities);
        options.setAutomationName("XCUITest");
        options.setPlatformName("iOS");
        options.setDeviceName("iPhone 11");
        options.setPlatformVersion("14.1");
        options.setApp("/Users/alekseigerasimov/1/UIKitCatalog.app");

        System.out.println(options);
        try {
            return new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), options);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
}

Error: 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’)

Capability are:
Capabilities {appium:app: /Users/alekseigerasimov/1/U…, appium:automationName: XCUITest, appium:deviceName: iPhone 11, appium:platformVersion: 14.1, platformName: IOS}

Upgraded selenium-java version to 4.2.2 and Appium java client to 8.1.1. Build your project, run your script. This issue will no more come.