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.
XCUITestOptionsto create an XCUITestDriver instance
UiAutomator2Optionsto create a UIAutomator2Driver instance
EspressoOptionsto create an EspressoDriver instance
WindowsOptionsto create a WindowsDriver instance
Mac2Optionsto create a Mac2Driver instance
GeckoOptionsto create a GeckoDriver instance
SafariOptionsto 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);
- Like Selenium, Appium also removed all its
- Since Appium supports both mobile and desktop platform applications, we replaced
AppiumByand introduced camelCase naming conventions. For example,
MobileByis now deprecated.
windowsAutomationlocator strategy is deprecated.
Starting Appium Server Programmatically
- Java Client uses
AppiumServiceBuilderto 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
- 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-pathexplicitly while building the
// 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
SelendroidDriverclass is removed
SafariDriverare newly introduced drivers
GeckoDriveris an officially supported Appium driver to automate Mobile browsers and web views based on the gecko engine
SafariDriveris also an official driver for automating Safari on macOS and iOS
Changes in Element Classes
iOSElementclasses are removed. It is recommended to use
replaceValuemethod is now called
setValuemethod is removed in favor of the existing
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://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.
AppiumDriver methods like
launchApp have been deprecated as they are going to be removed from the future Appium versions. Alternatively, the suggested approach is to use
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.
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!