Setting up Appium in your machine might look a little intimidating because of the number of steps involved. We will go through each step one by one in Windows machine and ensure that you are able to run your first Appium script without any roadblock.
1) Install Java and set Java Environment Variable Path
Java Development Kit (JDK) is an application to create and modify programs in Java. To install Java in your system, download JDK from Oracle JDK Downloads page. After download, go through the installation process and complete it. Once installation is complete, go to your Environment Variables and set up JAVA_HOME as system/user variable and include %JAVA_HOME%\bin in your path variable. To check whether Java has been successfully installed or not, open your command prompt, type java -version and press Enter. It should display the JDK version that your system is currently referring to.
2) Install Android Studio and set Environment Variable Path
Android is an Operating System developed by Google for mobile devices. It is a platform that provides tools which we need to run our Appium Tests. You can download Android Studio from Google Android Developer website.
Once Android Studio is successfully downloaded, start installation. It will take some time to complete the installation process. After installation is complete, you should be able to see Android folder inside the Local folder of AppData (e.g C:/Users/AppData/Local/Android). By default, the AppData folder is hidden. Ensure that it is unhidden. To set the Android Environment Variable path:
- Go To Control Panel -> System and Security -> System
- Click on “Advanced system settings”
- Go to “Advanced” tab and click on “Environment Variables”
- In System Variables section, set ANDROID_HOME variable with the path of your Android SDK folder (image below)
- Edit the already existing “Path” variable and add the location of tools, tools\bin and platform-tools folder of Android SDK (image below)
- Click on OK and you are all set.
3) Open Android Studio and Configure Emulator (Virtual Device)
If you are not using Real Device to run your Appium Tests, you need to configure Emulator or Virtual Device from your Android Studio that you have just installed. Open Android Studio by clicking on icon. Once opened, click on the AVD Manager icon at the top right corner of Android Studio.
“Android Virtual Device Manager” window will open up. Click on “+Create Virtual Device” button below and perform the below steps to optimize the Virtual Device performance:
- Select any device (preferably Nexus5 or Nexus6)
- Click on “Clone Device“
- In Configure Hardware Profile window, give your Device a name
- Select Device Type as Phone/Tablet
- Edit Memory field to take 850 MB RAM (particularly if your System installed memory is 4GB/8GB)
- Uncheck all the checkboxes in Cameras and Sensors sections.
- Click on “Finish” button
- In Select Hardware window, click on Next button
- In System Image window, click on image (e.g. Pie/Oreo) to download. It will take some time to download.
- Verify the Configuration in AVD window and click on Finish. You will see an entry like below. Click on the Green “Play” button under the Actions column to start your virtual device.
Note:- To check whether your virtual device is running or not, go to command prompt, type the command adb devices and press Enter key. You should be able to see your virtual device.
4) Download and install Node.js
We need Node.js to run our Appium server. Go to Nodejs official download page, click on the LTS tab and download Windows Installer package (.msi) or Windows Binary (.zip). Once downloaded, install NodeJS. Like before, go to Environment Variables and set NODE_HOME variable with the location of nodejs folder in your Program Files (e.g. C:\Program Files\nodejs). Edit the Path variable and add %NODE_HOME%\;%NODE_HOME%\node_modules\npm\bin to its existing value. To check whether nodejs is successfully installed on your system, go to command prompt, type node -v and press Enter key. You should be able to see the version of nodejs you have installed.
5) Download Appium Server using npm (Node Package Manager)
If you have followed the previous step to install nodejs, then the Node Package Manager (npm) is already set in your system. To check whether npm is set or not, open command prompt, type npm -v and press Enter key. It will display the installed npm version. Now, to download Appium Server using npm, type the command npm install -g appium in command prompt and press Enter. It should start downloading all the packages and dependencies required for Appium Server to run. Once completed, you can check the Appium version installed by running the command appium -v. To start the Appium server, you need to use the command appium and to stop the server anytime you can use Ctrl+C command.
6) Download Appium Java Client Library
In this tutorial we will be running our Appium tests using Java and hence we require to download the Appium Java Client Library from the Appium official page. An executable jar file (e.g. java-client-7.0.0) will get downloaded. You also need to download Selenium Java Client Libraries (Download from Selenium official page) and Apache commons-lang3(Download from Apache Commons official page).