Resolving Session Creation Issues with Appium and Selenium Versions in Maven

Resolving Session Creation Issues with Appium and Selenium Versions in Maven

When using the latest version of java-client for Appium (currently 9.3.0) with Maven, you might encounter the following error:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Host info: host: 'Your-Host-Name', ip: '192.123.4.5'        

This issue arises because the latest version of java-client for Appium comes bundled with the latest version of Selenium (currently 4.23.1), which may not be fully compatible. Here’s what the Appium team has to say in their GitHub repository:

"Why is it so complicated? Selenium client does not follow Semantic Versioning, so breaking changes might be introduced even in patches, which requires the Appium team to update the Java client in response."
"How to pin Selenium dependencies? Appium Java Client declares Selenium dependencies using an open version range which is handled differently by different build tools. Sometimes users may want to pin used Selenium dependencies for various reasons. Follow the Transitive Dependencies Management article for more information about establishing a fixed Selenium version for your Java test framework."

What does this mean?

Selenium does not follow Semantic Versioning, meaning breaking changes can be introduced even in minor or patch updates. This requires the Appium team to frequently update the java-client to remain compatible with Selenium. This means that even minor updates in Selenium can cause incompatibility issues with Appium, leading to errors like the one mentioned above. Therefore, it's essential to manage the versions of these dependencies carefully.

Compatibility Matrix

In the Compatibility Matrix, the Appium team indicates which versions of Appium work best with which versions of Selenium. For example, version 9.3.0 of java-client is best paired with Selenium 4.23.0. Keeping this matrix in mind, we need to clean up our dependencies to avoid conflicts.


Solutions

There are two possible solutions based on the matrix:

(Select one of the two depending on the needs of your project.)

1. Exclude Selenium from Appium Dependency and Add Selenium Manually:

  • This method involves using the <exclusion> tag to prevent the appium java-client dependency from downloading its own Selenium dependency and instead manually adding the desired Selenium version.

Exclude Selenium from Appium Dependency

<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>9.3.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
        </exclusion>
    </exclusions>
</dependency>

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

2. Or Use Dependency Management to Pin Selenium Version:

  • This method allows Appium to download the Selenium dependency but uses the <dependencyManagement> section to ensure Maven uses a specific version of Selenium.

Use Dependency Management

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.23.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>9.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
    </dependency>
</dependencies>        

Finally

Compile your project with maven commands

mvn clean install        

Or if you have test cases and you just need to compile the project so that the dependencies are downloaded but you don't need the test cases to be executed

mvn clean install -DskipTests        

Conclusion

By following these steps, you can ensure that your Appium and Selenium versions are compatible, allowing you to create a new session successfully with the Appium server:

driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), capabilities);        

#Appium #Selenium #Maven #Java #AutomationTesting #TestAutomation #DependencyManagement #JavaClient #SoftwareTesting

To view or add a comment, sign in

Others also viewed

Explore content categories