Getting started with Appium 2.0: Your beginner’s guide
Tags: testing, mobile, qa, tutorial
Published: 2022-12-20 14:59:25

_A hands-on guide to help you to get started with Appium 2.0, the new features, and how to install and use it locally or on Bitrise._

## What’s Appium?

Appium is an open-source project and ecosystem of related software, designed to facilitate UI automation of many app platforms, especially for mobile apps such as iOS, Android, and Flutter.

Using Appium, you can automate your UI testing across any number of platforms in a standard way. Many tools allow UI automation on platforms, but these are typically platform-specific native tools such as Espresso for Android and XCUITest for iOS and require specific programming language knowledge and toolchains. 

The Appium framework aims to integrate all these automation technologies into a stable interface accessible through the most popular programming languages including Java, Python, Ruby, C#, and Javascript.


## Overview of Appium 2.0

[Appium 2.0](https://appium.github.io/appium/docs/en/2.0/intro/) (still beta) reenvisions Appium as a platform where “drivers” and “plugins” can be easily created and shared independently.


![1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyaetjp5ijhycf8hshmt.png)


- **Drivers:** gives you the ability to install and work with de-coupled drivers based on your application platform (iOS, Android, Windows OS, Flutter, such as Espresso driver  “appium driver install espresso”.
- **Plugins:** gives you the ability to modify the Appium framework by adding new features via plugins and through integrations with other technologies such as the images plugin: “appium plugin install images”, then activate the plugin with your server by “appium --use-plugins=images”
- **Appium Desktop:** is still available, but now comes in two **packages:**
   - Appium Desktop (Server) 
   - Appium Inspector


![2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6blzs20z7166kf0v14bm.png)

With Appium 2.0, you should also ensure you’re sending W3C standard capabilities within your test code such as the following capabilities:

```
{
  "platformName": "Android",
  "appium:platformVersion": "9",
  "appium:deviceName": "emulator-5554",
  "appium:automationName": "Espresso",
  "appium:app": "app-debug.apk"
}
```

## Getting started with Appium 2.0

Before getting started with Appium v2 you need to know the [requirements](https://appium.github.io/appium/docs/en/2.0/intro/requirements/), then with Appium 2.0 you need to follow the following steps:

Step 1: Install Appium v2

`npm install -g appium@next`

**NOTE:** Currently, you must use appium@next instead of just appium. Once Appium 2.0 has been officially published, you can simply use appium.

To make sure which appium version is installed, run the following command:

`appium -v`

The output should be `2.0.0-beta.46`

After installing Appium v2 you will have the ability to extend the CLI with plugin and driver commands. 

Step 2: Install an Appium driver and its dependencies
To install the Appium driver and its dependencies, we'll be using the [Espresso](https://github.com/appium/appium-espresso-driver), [XCUITest](https://github.com/appium/appium-xcuitest-driver), and [Flutter](https://github.com/appium-userland/appium-flutter-driver#installation) drivers.

```
appium driver install espresso
appium driver install xcuitest
appium driver install flutter
```
To make sure that all the drivers are installed successfully, run the following command:

` appium driver list`


![3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cp53bu60fkbcaa795ea.png)

Step 3: Install the plugins
To install the plugins, run the following command to get a list of the available plugins and then install any of them: 

` appium plugin list`

![4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e46431mhbdhr52eug80o.png)

To install any plugin, such as images, use the following command:

` appium plugin install images
`

![5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/laomku3k4hjzy4fmblnv.png)

And to use it with the Appium server, use the following command: 

` appium --use-plugins=images 
`

To run the Appium Server, use the Server GUI or the command line, for example: 

` appium server -ka 800`

Or the GUI application:


![6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9lzcg8ofhm21glyhaap.png)

And if you want to inspect the elements, you need to open the Inspector application:

![7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hr5wurvmn3ajg56h011s.png)


Step 4: Install the Appium client library
Install an Appium client library in your language or choice (we’ll be using the Java client with Maven).

Step 5: Run an Appium automation script
Write and run a simple Appium automation script using a sample application.

```
public class AppiumAndroidTest {
    public static AppiumDriver driver;

    @BeforeClass
    public void Android_setUp() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("appium:automationName", "espresso");
        capabilities.setCapability("appium:platformVersion", "9");
        capabilities.setCapability("appium:deviceName", "Android Emulator");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appium:app", System.getProperty("user.dir") + "/apps/app-debug.apk");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), capabilities);
    }

    @Test
    public void calcDemo(){
        driver.findElement(By.id("buttonFive")).click();
        driver.findElement(By.id("buttonAdd")).click();
        driver.findElement(By.id("buttonFour")).click();
        driver.findElement(By.id("buttonEqual")).click();
    }

    @AfterClass

    public static void tearDown() {
        if (null != driver) {
            driver.quit();
        }
    }
}
```
You can find the full project in this [GitHub repository](https://github.com/moatazeldebsy/bitrise-appium/tree/demo). 

Now, you can run your project locally, but as you know it’s required to have an Android Emulator and iOS Simulator installed. 

The Appium Troubleshooting Guide
Using appium-doctor, you can verify your installation and manually install anything that is missing if necessary.

You will notice that [appium-doctor](https://www.npmjs.com/package/appium-doctor) is deprecated 

![8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ka9c81775zz9jy1vki7.png)

And you can install it using the following command as mentioned here:

` npm install @appium/doctor -g`

You can check the iOS and Android setup by running the following command:

` appium-doctor 
`
If something is wrong, you can fix it manually and run the command again.


![9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54exdybb0gd6j7u65gro.png)


![10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/790ir3reywk2g8ymcot7.png)

If you are facing issues with Appium with iOS apps — or can’t run your tests on iOS real devices — check out how to set up iOS real devices and also Enable the Developer Mode on the device.

- [Setting up iOS Real Devices Tests with XCUITest](https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md)
- [Enabling Developer Mode on a device](https://developer.apple.com/documentation/xcode/enabling-developer-mode-on-a-device)

If you are facing a problem with the WebDriverAgent — or can’t be installed on the device — you can also try to locate the Xcode project. Add your team account in the code signing setting and try to build the app for an iOS device to make sure that there is no problem. 

You can use the following command to find the project directory:

`echo "$(dirname "$(find "$HOME/.appium" -name WebDriverAgent.xcodeproj)")"` 

And the output will give you the path of the project

![11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmouifcdf7jk9p3mlgdh.png)

Open the project in Xcode, add a team or your developer account and build the project to make sure that there is no issue with the WebDirverAgent. 

![12](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2q0up8slwymgeo2exzsg.png)

## Migration from Appium 1.x to Appium 2.x

Here is a [guide](https://appium.github.io/appium/docs/en/2.0/guides/migrating-1-to-2/) that walks you through some potential breaking changes and other useful tips for migrating your test code from Appium 1.x to Appium 2.x.

## Utilize Bitrise's CI/CD Workflow to run Appium tests

[Bitrise](https://www.bitrise.io/) and [Appium](https://blog.bitrise.io/post/getting-started-with-appium-bitrise-for-android-apps) integrate seamlessly. You can run your test automation with Appium on virtual devices in the cloud without needing to use a 3rd party cloud service. 

For testing mobile applications on Bitrise and Appium, you’ll be able to:

- Integrate test automation into your CI/CD pipelines.
- Multiple platforms can be used to scale your existing Appium testing.
- Using the [Test Report add-on](https://devcenter.bitrise.io/en/testing/test-reports.html) to find and fix bugs faster.


The integration is simple and straightforward, I created a Bitrise integration step to simplify the installation of the Appium Server, Drivers (XCUITest, Espresso, and Flutter) and run the server as a background task. 

You need only to add the [Step](https://www.bitrise.io/integrations/steps/appium-server) in your Bitrise Workflow and in case you need to run UI tests on Android you need to spin up the emulator first but with iOS, the execution will initialize the Simulator.

![13](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nxbdq0635yvltpooqnt0.png)


![14](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3nn423i0mosof6ipag0.png)

Run the UI tests via the Maven command

![15](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e1sdnb0lfpy8y1ow4bn2.png)

Copy the Appium Log to the Deploy directory to view it via the Artifacts section

![16](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dn7d3aewkqkguqeq3e05.png)

Finally, export the test results to the Test Report add-on. 

![17](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fzurbjdh3kjjcij9sks.png)

Run the Build and the results should be like the following images.

![18](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qbz0any8k6033mj5lm2.png)

![19](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ociylw89w3z6ljgmrxwp.png)

![20](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jctb33xipo93iqvgsjlr.png)

![21](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aliiudamdq3h6vsgd66h.png)

![22](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r92knu6u1l694yozu6e3.png)

![23](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zkog8jaa18ppkhn3z4cu.png)

Congratulations 🎉, you have successfully run your Android and iOS test cases with Appium v2 on Bitrise. 

## Resources

In this section, you'll find links to additional Appium resources around the web, including my Appium course with Test Automation University.

[Appium Resources](https://appium.github.io/appium/docs/en/2.0/resources/)