A software library is a set of data and programming code that is used to develop software applications. It is designed to assist both the programmer and the programming language compiler in building and executing software. The benefits of keeping software libraries updated include bug fixes, new features, boosted performance, as well as better stability, compatibility, and security measures.
In this blog, we will share some of our key learnings from migrating Appium Java Client v7 to v8.
This is the Java language bindings for writing Appium Tests that conform to WebDriver Protocol
As there are several major changes in Appium java client version 8, we have to update the client code.
Adding Appium java client to your test framework
Major differences between Appium Java Client v7 vs v8
The following are the list of major changes between major versions 7 and 8 of Appium java client.
Strict W3C specification compatibility
Now Java client supports Selenium 4, which means it is strictly W3C compliant. Previously, JSON wire protocol acts as a mediator between client libraries and WebDrivers. It transfers data between the client and the server on the web. The server doesn't understand the programming language in which the program is created, it just understands the protocol. Old JWP -based servers are not supported anymore, and it won't be possible to use the new client version with them.
The recommended way to provide capabilities for driver creation is to use specific option builders inherited from BaseOptions class. For example XCUITestOptions to create a XCUITest driver instance or UiAutomator2Options to create an UiAutomator2 driver instance. If there is no driver-specific options class for your driver then either use BaseOptions builder as the base class to define your capabilities or request driver developers to add one. Do not use DesiredCapabilities class in order to develop driver-specific options in W3C context. Some of the capabilities are defined for android using UiAutomator2Options.
- All findBy* shortcut methods(e.g. findElementById, findElementByClassName, findElementByLinkText,...) were removed. Consider using findElement[s](By. or AppiumBy.) instead.
- MobileBy class has been deprecated. Consider using AppiumBy instead.
- All locator names in AppiumBy have been aligned to follow the common (camelCase) naming strategy, e.g. MobileBy.AccessibilityId was changed to AppiumBy.accessibilityId.
- As part of changes in Selenium 4, class name selector strategy will not work in Appium. AppiumBy.className should be used instead of Selenium's By.className now.
All methods that use TimeUnit class or where the time is passed as a simple numeric value were replaced with their alternatives using java.time.Duration class.
- All AppiumDriver descendants and the base class itself are not generic anymore and only work with WebElement interface.
- The base Appium driver does not extend ContextAware, Rotatable and other mobile-specific interfaces. Instead, it only has the very basic set of methods. Mobile specific methods have been respectively moved to AndroidDriver and IOSDriver.
- "HasSessionDetails" interface which provide access to getSessionDetails has been removed as it was using legacy JWP calls to retrieve session details.
- "DefaultGenericMobileDriver" class has been removed. Now AppiumDriver is inherited directly from Selenium's RemoteWebDriver.
- "DefaultGenericMobileElement" class has been removed completely together with its descendants (MobileElement, IOSElement, AndroidElement etc.). Use WebElement instead.
- Due to the above change the page factory is now only creating elements that are instantiated from RemoteWebElement and implement WebElement interface.
- If you used some special methods that MobileElement or its descendants provided then change these: (i) replaceValue has been moved to the corresponding AndroidDriver instance and is called now replaceElementValue (ii) use sendKeys method of WebElement interface instead of setValue.
The TouchAction and MultiTouchAction classes have been deprecated. The support of these actions will be removed from future Appium versions. Please use W3C Actions instead or the corresponding extension methods for the driver (if available). The following method shows for swipe down using W3C Actions and the code is self explanatory with comments and it is as simple as how we perform action with our fingers on mobile.
AppiumDriver methods resetApp, launchApp and closeApp have been deprecated as they are going to be removed from future Appium versions. The following method can be helpful to launch App by using startActivity method and ResetApp by using clearApp and StartActivity methods.
Now the “/wd/hub” is truncated from the the URL we provide during driver instantiation (e.g. http://0.0.0.0:4723/wd/hub became http://0.0.0.0:4723/). This has been done in order to align the actual behavior with
Appium v2. If you still using Appium server v1.2x with Appium Java Client v8, where the server URL contains the /wd/hub suffix by default, then consider providing --base-path setting explicitly while building AppiumServiceBuilder instance (e.g. .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")). Older versions of Appium server (v1.19 and older) won't work with AppiumDriverLocalService, because they don't allow provisioning of base path in form of a command line argument.
I will briefly explain how to install Appium v2. Prerequisite to install appium 2 is to have node.js version 14+ and NPM 8+ version. Appium 2.0 can't be installed using
npm install -g appium, it still install appium 1.x because version 2 is still in beta release. So we can install appium 2 using
npm install -g appium@next but with this command drivers and plugins are not installed.
Appium 2.0 decouples its supported WebDrivers, hence we can choose to install only required drivers and plugins. For Android we can install UiAutomator2 and for iOS we can install XCUITest driver with
appium driver install uiautomator2 and
appium driver install xcuitestcommands respectively. Driver can be updated by
appium driver update <driverName> and driverName is the name of the driver as printed in the output of
appium driver list --installed.
The above list should help us to successfully migrate our existing automated tests/scenarios from version 7 to 8. Capabilities that enforce the usage of JWP on Appium drivers don't have any effect anymore. With Appium Java Client v8 as MobileElement is replaced by WebElement, a single framework can be used across all platforms(Web, Android and iOS). It is good to update the Appium Java Client to latest stable version, use Appium 2+ and install required driver and plugin as per your requirements to speed up automation execution time and for bug fixes.
Scalability, reliability, and maintainability are the three pillars that govern what we build at Halodoc Tech. We are actively looking for engineers at all levels and if solving hard problems with challenging requirements is your forte, please reach out to us with your resumé at email@example.com.
Halodoc is the number 1 all around Healthcare application in Indonesia. Our mission is to simplify and bring quality healthcare across Indonesia, from Sabang to Merauke. We connect 20,000+ doctors with patients in need through our Tele-consultation service. We partner with 3500+ pharmacies in 100+ cities to bring medicine to your doorstep. We've also partnered with Indonesia's largest lab provider to provide lab home services, and to top it off we have recently launched a premium appointment service that partners with 500+ hospitals that allow patients to book a doctor appointment inside our application. We are extremely fortunate to be trusted by our investors, such as the Bill & Melinda Gates Foundation, Singtel, UOB Ventures, Allianz, GoJek, Astra, Temasek many more. We recently closed our Series C round and In total have raised around USD$180 million for our mission. Our team works tirelessly to make sure that we create the best healthcare solution personalised for all of our patient's needs, and are continuously on a path to simplify healthcare for Indonesia.