What Is New In Appium 2.0?

Appium 2.0 beta version was launched in 2021 and Now Appium has officially released version 2.0. With this release, major changes have been introduced in Appium, which can break the already running test suites.

In this Appium 2.0 migration guide, I have tried to list the known changes that can break the existing code. I have also included a list of steps by following which you can easily migrate from Appium 1 to Appium 2.

Appium 2 Features

In this section, I will walk through the changes in Appium 2 and its dependencies.

Appium 2 Installation

To install Appium 2 execute the below command from the terminal.

 npm i -g appium@next

This command will install the latest version. To check the installed Appium version use the below command.

appium -v

You will see that the latest Appium 2 version is installed but there are no drivers attached to it.

Appium 2.0 Migration Guide

Driver Installation

From Appium 2.0 drivers can be installed/uninstalled or updated independently. For example, if an update is available for XCUITest then rather than waiting for a new Appium server release we can update the driver only by using CLI commands.

Earlier in Appium 1.0 drivers used to be installed along with the installation of the Appium Server.

Now let’s see how we can install the Android driver and IOS driver.

Install IOS Driver in Appium 2:

Drivers can be installed using the install command.

appium driver install xcuitest

Install Android Driver in Appium 2:

Similarly, install the Android driver by executing the below command.

appium driver install uiautomator2

Once the above two commands are successfully executed we should be able to see both the drivers installed.

Driver [email protected] successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]

How to Update Driver:

If there is an update available for the already installed driver in Appium 2 we can update it by using the below command. We don’t need to update the whole Appium version.

appium driver update xcuitest

Update Multiple drivers :

Similarly, if we want to update multiple drivers at once, we can simply provide the driver name separated by a comma with the update command. Refer below command.

appium driver update xcuitest,uiautomator2
# appium driver update driver1,driver2,driver3

After driver installation, if you restart the Appium then you will see your installed drivers under the “Available drivers:” section.

How to check all available/Installed drivers

To check what drivers have been installed already and what is available for installation, execute below mentioned command on the terminal.

appium driver list

This will give you a list of available drivers.

 Listing available drivers
- [email protected] [installed (npm)]
- xcuitest [not installed]
- mac2 [not installed]
- espresso [not installed]
- safari [not installed]
- gecko [not installed]
- chromium [not installed]

Server Base Path

The server base path has been changed from “http://localhost:4723/wd/hub” to “http://localhost:4723/” in Appium 2.0.

Protocol

Appium 1. X supported Mobile Json wire protocol however Appium 2. X uses the W3C WebDriver protocol.

Capabilities In Appium 2.0

In Appium 2. X User needs to include the vendor prefix in the non-standard capabilities names. For Example, if you wish to provide deviceName in capabilities, it should consist of the vendor prefix “appium:deviceName“. Only the browser name and platform name capabilities will not have the vendor prefix in the newer version.

Appium 1 (Older way):

Earlier in the Appium 1. x version we used to define capabilities using the DesiredCapabilities class to set various properties and preferences that define how an automation session should be established with a mobile device or an emulator.

DesiredCapabilities androidCaps = new DesiredCapabilities();
       androidCaps.setCapability("deviceName", "Pixel XL API 30");
       androidCaps.setCapability("automationName", "UIAutomator2");
       androidCaps.setCapability("udid", "emulator-5554"); 
       androidCaps.setCapability("platformName", "Android");

     androidCaps.setCapability("app",System.getProperty("user.dir") + "/src/test/resources/files/Bilgikolik.apk");
               
      androidCaps.setCapability("appPackage", "com.testapp.app");
      androidCaps.setCapability("appActivity", "com.testapp.app");
  driver = new AndroidDriver(newURL("http://127.0.0.1:4723"),androidCaps);

Appium 2 Capabilities

In Appium 2, we use the UiAutomator2Options class that provides information to Appium about the desired configuration for the test session. Refer to the below code.

UiAutomator2Options capabilities = new UiAutomator2Options();
 capabilities.setPlatformName("Android").setAutomationName("UIAutomator2")
               .setAppPackage("Package Name").setAppActivity("Activity Name")
               .setApp("App Path");
AndroidDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/"),capabilities);

Appium Inspector

Appium 2.0 segregated Appium Inspector from Appium Desktop. Also, the Appium team provided the browser version of the Appium inspector.  To test against local servers, you’ll need to start the server with --allow-cors so that the browser-based version of Appium Inspector can access the Appium server to start sessions.

Changes In Drivers and Classes

  • SelendroidDriver class is removed.
  • In Appium 2. X, it’s mandatory to know the port as it should be greater than zero. Earlier in Appium 1.x we could start the Appium Server with a port set as 0.
  • MobileElement classes including AndroidElement and iOSElement classes are removed. It is recommended to use WebElement.
@AndroidFindBy(xpath ="//android.widget.TextView[@text='Continue']")
 private WebElement Continue;
  • Mobile By Class has been removed, and AppiumBy Class has been introduced.

Older Way(Appium 1.x):

driver.findElement(MobileBy.id("loginbutton")).click();

New Way(Appium 2.x):

driver.findElement(AppiumBy.id("loginbutton")).click();
  • All locator names in AppiumBy have been aligned to follow the camelCase naming strategy, e.g. MobileBy.AccessibilityId was changed to AppiumBy.accessibilityId.
  • Appium Driver is directly inherited from Selenium’s RemoteWebDriver. There is no intermediate layer between AppiumDriver and RemoteWebDriver.
  • ResetApp, launch apps, and closeApp methods have been depreciated.
  • Appium Inspector is split out from Appium Desktop. Appium Inspector can be used with its web version without downloading anything.

TouchAction/MultiTouchAction

From Appium 2.0 both TouchAction and MultiTouchAction classes have been depreciated.W3c Action API will be used for automating gestures. For Example, the double-click gesture can be achieved using the below code:

driver.executeScript("mobile: doubleClickGesture", ImmutableMap.of(
   "elementId", ((RemoteWebElement) element).getId());

Plugins

Now anyone can write and publish a plugin to use with Appium. Customization will be easy by using those plugins.

To list down all the plugins use the command:

appium plugin list

This will list down all the available plugins. Users can choose any plugin from the list and install it per the requirement.

appium plugin install pluginname

Similarly, any installed plugin can be installed using the below-mentioned command.

appium plugin uninstall <plugin name>

Now you have successfully understood Appium 2.0 changes in this Appium 2.0 migration guide. Next, visit this article to learn how to start with Appium 2.0.

Discover more from AutomationQaHub

Subscribe now to keep reading and get access to the full archive.

Continue reading