
Learn about the latest updates in the Appium Java Client 8.0.0 release, and how it affects your Appium mobile testing today. Sai Krishna and Srinivasan are members of the Appium team.
The Selenium team released Selenium 4 in September 2021 to much anticipation with tons of great features. Since then, the Appium team has been working on upgrading the Selenium dependency in all the clients of Appium to provide a seamless experience. Most of the Appium clients are updated and now in early beta, but with a lot of breaking changes. Let’s go through the changes introduced in Appium Java client 8.0.0 beta2 and what you would need to do.
With Appium 2.0, we on the Appium team are making sure we are strictly W3C compliant. Since the Java client supports Selenium 4.1.1, it’s strictly W3C compliant too. Methods that are non-w3c complaint are removed and the details can be seen here.
It is now recommended to use driver-specific W3C option classes instead of Desired Capabilities. Below is the list of driver-specific classes.
XCUITestOptions to create an XCUITestDriver instance UiAutomator2Options to create a UIAutomator2Driver instanceEspressoOptions to create an EspressoDriver instanceWindowsOptions to create a WindowsDriver instanceMac2Options to create a Mac2Driver instanceGeckoOptions to create a GeckoDriver instanceSafariOptions to create a SafariDriver instanceSee the below example for changes required:
// From Appium Java Client version 8.0.0 Beta
UiAutomator2Options options = new UiAutomator2Options()
.setDeviceName("Android Emulator")
.setApp(System.getProperty("user.dir") + "/VodQA.apk")
.eventTimings();
driver = new AndroidDriver(service.getUrl(), options);
// Older approach: Java Client version 7.X.X
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 700000);
findBy methods.MobileBy with AppiumBy and introduced camelCase naming conventions. For example, MobileBy.AccessibilityId is now AppiumBy.accessibilityId. MobileBy is now deprecated.windowsAutomation locator strategy is deprecated.AppiumServiceBuilder to start a node server programmatically. With the updated version, it works slightly differently with different Appium server versions./wd/hub by default.–base-path explicitly while building the AppiumServiceBuilder.// From Appium 2.0 Beta
AppiumDriverLocalService service;
service = new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(4723)
.build();
service.start();
// Older approach: Appium 1.22.X
AppiumDriverLocalService service;
service = new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub")
.usingPort(4723)
.build();
service.start();
SelendroidDriver class is removedGeckoDriver and SafariDriver are newly introduced drivers
GeckoDriver is an officially supported Appium driver to automate Mobile browsers and web views based on the gecko engineSafariDriver is also an official driver for automating Safari on macOS and iOSMobileElement classes including AndroidElement and iOSElement classes are removed. It is recommended to use WebElement instead.replaceValue method is now called replaceElementvalue in AndroidDriver classsetValue method is removed in favor of the existing sendKeys method.The TouchActions and MultiTouchActions classes for automating gestures from your client code have been deprecated. Support for these actions will be removed from future Appium versions. It is recommended to use W3C Actions instead or the corresponding extension methods for the driver (if available).
Point source = slider.getLocation();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence sequence = new Sequence(finger, 1);
sequence.addAction(finger.createPointerMove(ofMillis(0),
PointerInput.Origin.viewport(), source.x, source.y));
sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.MIDDLE.asArg()));
sequence.addAction(new Pause(finger, ofMillis(600)));
sequence.addAction(finger.createPointerMove(ofMillis(600),
PointerInput.Origin.viewport(), source.x + 400, source.y));
sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.MIDDLE.asArg()));
driver.perform(singletonList(sequence));
Refer to the links below to know more about how to work with gestures:
AppiumDriver methods like resetApp, closeApp and launchApp have been deprecated as they are going to be removed from the future Appium versions. Alternatively, the suggested approach is to use removeApp, installApp, and activateApp methods available here. The non-standard way for App Management in iOS is using the mobile: methods to remove the app then install the new application and launch it using the methods here. For Android UIAutomator2 backend, the non-standard mobile: methods like clearApp deletes all data associated with a package, and installMultipleApks allows users to install multiple applications at the same time.
The current event firing mechanism that Appium Java Client uses has been deprecated in favor of the one that Selenium 4 provides natively. Read The-event_firing.md for more details on how to use it.
There are a lot of great new changes in this latest Appium Java Client update. You can check out a detailed migration guide here in Appium’s Java Client for reference. Do let us know where there’s been a problem, and thank you. We only have a chance to improve when we know that there’s something that needs work!
The update replaces DesiredCapabilities with driver-specific classes like XCUITestOptions, UiAutomator2Options, and EspressoOptions. These classes improve compatibility and make it easier to configure drivers specific to each platform.
The new approach uses AppiumServiceBuilder to start a node server without specifying /wd/hub as the base path. If using Appium 1.2.x, you’ll need to set the base path explicitly.
The MobileElement classes, including AndroidElement and iOSElement, have been removed. Instead, WebElement is now recommended for a more streamlined API.
These classes were deprecated in favor of W3C Actions, which offer a more universal approach to performing touch gestures. W3C Actions are also more aligned with modern WebDriver standards for gestures.
Appium now uses Selenium’s native event-firing mechanism instead of its own. This update simplifies event management and aligns with Selenium 4 standards for better integration and reliability.