seleniumappiumappium-androidappium-java

AndroidDriver cant be initialized after mvn clean


As usually, before running mvn test i executed mvn clean, but this time a lot of things started downloading, once it finished i ran the code and got this error:

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 actually didnt change anything, it just stop working (Last time I checked that this worked was 1 week ago)

This is the code that generates the error:

DesiredCapabilitiescap = new DesiredCapabilities();
URL url = new URL("http://0.0.0.0:4723/wd/hub");
cap.setCapability("platformName", "Android");
cap.setCapability("deviceName", "emulator-5554");
cap.setCapability("avd", "Pixel_4_API_30");
cap.setCapability("appPackage", "com.myapp.dev");
cap.setCapability("appActivity", "com.myapp.splash.SplashActivity");
cap.setCapability("appWaitActivity","com.myapp.fulllogin.WelcomeActivity");
cap.setCapability("automationName", "UiAutomator2");
cap.setCapability("noReset", "false");
AppiumDriver driver = new AndroidDriver(url, cap);

Solution

  • There could be version incompatibilities. When I got the same error, I made the following changes and it worked:

    In the pom.xml upped the version of java-client to 8.1.0 and added additional dependency selenium-support with compatible version 4.2.0

      <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>8.1.0</version>
      </dependency>
    
      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>4.2.0</version>
      </dependency>
    

    Optionally, made changes to the way capabilities are set for platform. Replaced capabilities.setCapability("platformName", "android") with capabilities.setCapability("appium:platformName", MobilePlatform.ANDROID)

    import io.appium.java_client.remote.MobilePlatform;
    ...
    
    DesiredCapabilities capabilities = new DesiredCapabilities();
    ...
    capabilities.setCapability("appium:platformName", MobilePlatform.ANDROID);