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.
WebDriver Protocol Compliance
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.
Driver-Specific Options Classes
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 instanceUiAutomator2Options
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 instance
See 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);
Element Lookups
- Like Selenium, Appium also removed all its
findBy
methods. - Since Appium supports both mobile and desktop platform applications, we replaced
MobileBy
withAppiumBy
and introduced camelCase naming conventions. For example, MobileBy.AccessibilityId
is nowAppiumBy.accessibilityId
.MobileBy
is now deprecated. windowsAutomation
locator strategy is deprecated.
Starting Appium Server Programmatically
- Java Client uses
AppiumServiceBuilder
to start a node server programmatically. With the updated version, it works slightly differently with different Appium server versions. - The default URL for the server has been changed at the server-side and it does not contain the
/wd/hub
by default. - Java Client starting from v8.0.0 has made required changes to align to Appium V2.
- If you still would like to use Java Client v8 with Appium 1.2.X then consider providing the
–base-path
explicitly while building theAppiumServiceBuilder
.
// 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();
Changes in Driver Classes
SelendroidDriver
class is removed- Both
GeckoDriver
andSafariDriver
are newly introduced driversGeckoDriver
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 iOS
Changes in Element Classes
MobileElement
classes includingAndroidElement
andiOSElement
classes are removed. It is recommended to useWebElement
instead.replaceValue
method is now calledreplaceElementvalue
inAndroidDriver
classsetValue
method is removed in favor of the existingsendKeys
method.
Touch Actions
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:
- https://www.youtube.com/watch?v=oAJ7jwMNFVU
- https://appiumpro.com/editions/30-ios-specific-touch-action-methods
- https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/android-mobile-gestures.md
- https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures.md
- https://appiumpro.com/editions/29-automating-complex-gestures-with-the-w3c-actions-api for more details on how to properly apply W3C Actions to your automation context.
App Management
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.
Appium Event Listeners
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.
Summary
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!
Quick Answers
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.