How to Start with Appium

If you are new to Mobile automation testing and have only heard about the Appium but do not know anything about it. No worries!!

This blog will help you to understand what is Appium and how it is useful. Also, it will guide you until you run your first program. Cheers!!

What is Appium?

Appium is an Open source tool to automate Mobile Applications Appium can be used to automate Native, web, and Hybrid mobile applications. It supports Android, iOS, and Windows desktop platforms. We can write appium scripts in multiple programming languages ex- Java, python, C#, PHP, etc.

What are Native, Web, and Hybrid mobile applications?

Native: Native Mobile Applications are those applications that are native to mobile. For example, applications like – Calculator, Gallery, etc.

Web: Web mobile applications are which we open in the mobile Web browser. Example – Opening any website link in the mobile web browser.

Hybrid: Hybrid mobile applications are those applications that are a combination of both Native and Web mobile applications. Example – Facebook, Appboss. These applications are mostly Native but they open external links in a web form (basically known as in-App browser).

Install Appium:

There are two ways to install Appium.

1- Install Appium with Node.js

2- Install Appium with Appium Desktop client

We will see both the methods, let’s start with first-

First - Install Appium with Node.js

Step 1– Check if Node,js is installed in your system. To do so –

  • Open Command line (cmd)
  • Enter –node –version or  node -v

npm –version or  npm –v

If these are already Installed then – Great but If not then we have to first install them.

Step 2- Download Node.js installer.

https://nodejs.org/en/download/

Step 3- Run the installer and install Node.js & npm

When the installation of Node.js is done then again open the cmd & run the same commands.

node –version   or  node -v

npm –version    or  npm –v

You can also check the location of the node installed on your system with below command-

where node

where npm

Step 4- Install Appium with Node.js

Run this command in cmd- npm install -g appium

Appium installation will start and when it’s done, Run below command to check if appium installation is successful.

appium –version

Appium version will be displayed.

To check the location of Appium – where appium

Step 5- Start Appium-

Run command in cmd – appium

Step 6- Stop Appium

To stop Appium just press ctrl+c on your keyboard, and then enter Y in cmd.

This is how we install Appium by using node.js. Now let’s see how we can install using the Appium desktop client.

Second- Install Appium with Appium desktop client

Step 1- Download Appium Desktop Client

http://appium.io/

https://github.com/appium/appium-desktop/releases/

Step 2- Install it

Step 3- Run

**Note- At a time we can only run Appium in one place. We cannot run Appium with Node.js and Appium desktop client at the same time as both will run on the same port.

Second- Install Appium with Appium desktop client

https://github.com/appium/appium-doctor

Step 1- Install Appium Doctor

Run command in cmd – npm install appium-doctor -g

Step 2- To check the Usages of appium doctor

Run command – appium-doctor -h

This command will list down multiple commands to check different functionalities.

➜  appium-doctor -h

Usage: appium-doctor.js [options, defaults: –ios –android]

Options:

–ios       Check iOS setup                                              [boolean]

–android   Check Android setup                                   [boolean]

–dev       Check dev setup                                              [boolean]

–debug     Show debug messages                                [boolean]

–yes       Always respond yes                                         [boolean]

–no        Always respond no                                           [boolean]

–demo      Run appium-doctor demo (for dev).           [boolean]

-h, –help  Show help

Now we will learn to connect real Android devices on windows , So that we can start with our mobile automation.

PREREQUISITES

– Java installed on system

 JAVA_HOME is set in environment variables

To check if Java is installed in your system, run command in cmd- java -version

 An android mobile device

– Connecting cable

 at least 200 MB free space

Step 1- Download SDK Product Management Techniques

https://developer.android.com/studio

Step 2- Unzip folder & Extract platform-tools

Step 3- Set environment variables

ANDROID_HOME = location of SDK folder

PATH: append the path of platform tools folder

Step 4- To check if platform tools are installed correctly. Run below command in cmd

ADB Devices

If it does not provide any error then you are good to go.

Step 5– Make device ready

  • enable developer mode in your device
  • Allow USB Debugging

Step 6- Connect the device to the computer system through USB cable

Step 7-  Run below command again in cmd

ADB Devices

Check your device id displayed.

Now your mobile device is connected to windows and you are ready to start mobile automation.

As promised in starting this blog will guide you until you run your first program using Appium. So now we will see a Java program to open any Application present in the mobile connection for automation. Let’s say “Gallery”

Step 1- Open Eclipse or any other IDE for Java

Step 2- Create a Project

I have created the Maven Project but you can create any project. The reason I have used the maven project is that it is very easy to arrange and download dependencies. We do not have to download dependencies and manage them manually. Also, when we take the project to another place or system then we do not have to care about dependencies, maven will take care of all of them.

Step 3- Add dependencies

  • Selenium dependencies
  • TestNg dependencies
  • Appium java client

https://mvnrepository.com/search?q=appium

Step 4- Connect your device to your system and Run below command

ADB Devices

Your device id will list down.

Step 5- Start Appium server

You can do it from command line or Appium desktop client

Step 6- Now we will write our code to open Gallery  application in the mobile connected

Public class FirstAppiumProject{

static RemoteWebDriver driver;

Public static void main(String[] args){

      Try{

          openGallery();   

}catch(Exception exp){

System.out.println(exp.getCause());

System.out.println(exp.getMessage());

exp.printStackTrace();

}

}

Public static void open gallery throws Exception(){

DesiredCapabilities capability = new DesiredCapabilities();

capability.setCapability(“deviceName”, “Pixel”);

capability.setCapability(“udid”, “524895cf”);

capability.setCapability(“platformName”, “Android”);

capability.setCapability(“platformVersion”, “10”);

capability.setCapability(“appPackage”, “com.myos.gallery”);      capability.setCapability(“appActivity”, “com.myos.gallery.gal”);  driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capability);

System.out.println(“gallery Application Started”);

Step 7– Run and Validate

**Note: Above mentioned capabilities are imported and you always need to provide them in your program to run the Appium code.

deviceName  — will be connected mobile device name

Udid — this will be the id which you get by running command ADB devices

platform name — Android

platform version — Android version of the connected device

app package — will be the package name of the Application you want to automate.

app activity — will be the activity of the application you want to automate

**Note– You can find the app package and app activity by using any App like Apk info on your device.

Thanks for holding this long with the blog. I hope you find it useful.

Vijay Kumar is the founder and admin of Wide4.com. After working with several digital marketing service providers in India, he has started his own blog where he helps internet users to solve issues in technology fields like hosting, VPN, website builder, and social media websites. He has 6+ years of experience in digital marketing and his areas of expertise include SEO, SMO, ORM, and Inbound marketing. You can connect with Vijay on Linkedin: Click here