Setting up Appium

Reading Time : 11min read
Setting up appium

Appium is platform-independent, so executing Appium scripts is largely consistent across all the major platforms (Linux, Mac, and Windows). Appium can significantly elevate your mobile testing with its cross-platform compatibility, scalability, and cost-efficiency. Additionally, platforms like Kobiton also makes Appium run faster.

In this article, we will discuss how can you setup and install Appium and its dependencies on different platforms.

Installing Appium on Windows

Software required:

Install the JDK software and set JAVA_HOME

Install the Java Development Kit Software

• Go to: https://java.sun.com/javase/downloads/index.jsp
• Select the appropriate JDK software and click Download
• The JDK software is installed on your computer, for example, at C:\Program Files\Java\jdk1.6.0_02. You can move the JDK software to another location if desired.

Set JAVA_HOME:

• Right click My Computer and select Properties.
• On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, like: C:\Program Files\Java\jdk1.6.0_02.
• You can check it by typing $ java -version command at the command prompt

image of JAVA_HOME system variable

Figure-1: JAVA_HOME System Variable.

image of PATH system variable

Figure-2: PATH System Variable.

Install the JDK software and set ANDROID_HOME

Install Android Studio and the SDK

• Go to: https://developer.android.com/studio/index.html
• Download and Install Android Studio
• Open Android Studio and then download the needed Android SDK files from Tools > Android > SDK Manager

Set ANDROID_HOME:

• Right click My Computer and select Properties.
• On the Advanced tab, select Environment Variables, and then add ANDROID_HOME to point to where the Android SDK files is located, like: D:\Android\sdk\
• Verify it on the Command prompt using $ echo %ANDROID_HOME% command. Output must display the SDK path.

Figure-3: ANDROID_HOME System Variable.

Installation of Node.js

Install Node.js from: https://nodejs.org/en/download/

You can verify installation by entering $ npm -v  command at the command prompt and it will display the version.

image of Node.js version

Figure-4: Node.js version

Installation of Appium desktop server

Go to the Appium github project and Download the relevant Appium Desktop .exe file.

Install it and Open Appium.exe file and start the server

image of appium desktop application

Figure-5: Appium Desktop Application

A Terminal should appear saying ‘The server is running’

image of appium server running on 0.0.0.0:4723

Figure-6: Appium Server is running on 0.0.0.0:4723

Please follow the above steps correctly in order to have a seamless Appium setup experience.

Installing Appium on Mac

Software required:

  • Java
  • Android SDK (Android Studio)
  • Node.js
  • XCode
  • Appium Desktop Server  

Install the JDK software

Install the Java Development Kit Software from: https://java.sun.com/javase/downloads/index.jsp

Select the appropriate JDK software and click Download.

Set JAVA_HOME:

• Right click My Computer and select Properties.
• On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, like: C:\Program Files\Java\jdk1.6.0_02.

Install Android Studio & Android SDK

Install Android Studio from: https://developer.android.com/studio/index.html

Open Android Studio and then download the needed Android SDK files from Tools > Android > SDK Manager

Set JAVA_HOME & ANDROID_HOME

We need to store Environment variables in .bash_profile file, so open Terminal and enter this command to open the bash_profile:

$ vi ~/.bash_profile

Now, you need to go into insert mode by pressing the `i` key from the keyboard, and write the following text at the end of the file.

export ANDROID_HOME=/Users/username/Library/Android/sdk
export ANDROID_SDK=$ANDROID_HOME
PATH=$PATH:$ANDROID_HOME/build-tools
PATH=$PATH:$ANDROID_HOME/platform-tools
PATH=$PATH:$ANDROID_HOME/tools
export PATH
export JAVA_HOME="`/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home`"

Press ESC key followed by :wq, which will save the .bash_profile file.

You can check that JAVA_HOME & ANDROID_HOME are properly set by executing commands $ java -version & $ echo $ANDROID_HOME Respectively.

image of ANDROID_HOME & JAVA_HOME environment variables

Figure-7: ANDROID_HOME & JAVA_HOME environment variables.

Installation of Node.js

Install Node.js from: https://nodejs.org/en/download/

You can verify the installation by entering $ npm -v  command at the command prompt and it will display the version.

Installation of the Appium desktop server

Go to the Appium github page and download the relevant Appium Desktop .dmg file.

Install it and Open Appium  and start the server

A Terminal should appear saying ‘The server is running’

image of appium desktop application

Figure-8: Appium Desktop Application

image of Appium Server running on 0.0.0.0:4723

Figure-9: Appium Server is running on 0.0.0.0:4723

XCode with Appium libraries setup

Install XCode: https://developer.apple.com/download/

Install Xcode Command line tools:

  • Execute below command on Terminal:
$ xcode-select --install

Install Brew(If it’s not installed already):

  • Execute below command on Terminal:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install libimobiledevice:

  • Execute below command on Terminal:
$ brew install libimobiledevice --HEAD

Install ios-deploy:

  • Execute below command on Terminal:
$ npm install -g ios-deploy

Install carthage:

  • Execute below command on Terminal:
$ brew install carthage

NOTE: Now you are set to run your iOS Appium Script on Simulator

WebDriverAgentRunner setup(Setting up iOS real devices tests with XCUITest)

This is the most crucial and important step of Appium setup for iOS. If you don’t follow these steps correctly, then you might not be able to run the Appium Automation scripts on your real iOS devices.

There are 2 ways to configure project in Appium:

  • Basic (automatic) configuration
  • Basic (manual) configuration

Automatic configuration

The easiest way to get up-and-running with Appium’s XCUITest support on iOS real devices is to use the automatic configuration strategy. There are two ways to do this:

Use the xcodeOrgId and xcodeSigningId desired capabilities:

{
  "xcodeOrgId": "<Team ID>",
  "xcodeSigningId": "iPhone Developer"
}

In Java, the code will look like:

desiredCapabilities.setCapability("xcodeOrgId", <<Team ID>>);      
desiredCapabilities.setCapability("xcodeSigningId", "iPhone Developer");

NOTE: You can always come back to this article after you’ve progressed in your Appium knowledge a bit further and need to start testing on real iOS devices (as compared to Emulators).

or

Create a .xcconfig file somewhere on your file system and add the following to it

DEVELOPMENT_TEAM = <Team ID>
CODE_SIGN_IDENTITY = iPhone Developer
desiredCapabilities.setCapability("xcodeConfigFile", "path/to/.xcconfig")

In either case, the Team ID is a unique 10-character string generated by Apple that is assigned to your team. You can find your Team ID using your developer account. Sign in to www.developer.apple.com/account, and click Membership in the sidebar. Your Team ID appears in the Membership Information section under the team name. You can also find your team ID listed under the “Organizational Unit” field in your iPhone Developer certificate in your keychain.After this you need to set the desired capabilities and set the path to .xcconfig file:

NOTE: These are mutually exclusive strategies; use either the xcodeConfigFile capability or the combination of xcodeOrgId and xcodeSigningId. For more details you can visit this link.   

Manual configuration

There are many cases in which the basic automatic configuration is not enough. This usually has to do with code signing and the configuration of the project to be able to be run on the real device under test. This often happens when the development account being used is a “Free” one, in which case, it is not possible to create a wildcard provisioning profile, and will often not create one for the default application bundle.

Please follow these steps to Manually configure the WebDriverAgent XCode project.

  • Move to the: WebDriverAgent.xcodeproj(Make sure you have installed Appium Desktop application properly):
    $ cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent$ sh Scripts/bootstrap.shExecute the Scripts/bootstrap.sh script using:
  • Open the WebDriverAgent.xcodeproj project in Xcode.
image of WebDriverAgent.xcodeproj Project in Finder window

Figure-10: WebDriverAgent.xcodeproj Project in Finder window.

  • Select WebDriverAgentRunner under TARGETS.
  • Now when you move to WebDriverAgentRunner, you would face an error that Xcode failed to create provisioning profile:
image of XCode: WebDriverAgentRunner Project in not able to find Provisioning profile

Figure-11: XCode: WebDriverAgentRunner Project in not able to find Provisioning profile.

  • The easiest way to resolve that is 1) Select WebDriverAgentLib under TARGETS, 2) select Automatically manage signing, 3) select valid Team and most important 4) change the Bundle Identifier and put the Bundle Identifier of your existing valid XCode project the purpose here to put something that Xcode will accept.
image of XCode: Change Bundle Id, Select  and Select Valid Team Project

Figure-12: XCode: Change Bundle Id, Select  and Select Valid Team Project\

  • Also ensure that you should have installed the valid Provisioning profile(Of course compatible with entered Certificate and Bundle Identifier). Now move to WebDriverAgentRunner again and 1) Select valid Provisioning Profile under Signing (Debug) and 2)  Select valid Provisioning Profile under Signing (Release).
image of XCode: Select Valid Provisioning Profile for WebDriverAgentRunner

Figure-13: XCode: Select Valid Provisioning Profile for WebDriverAgentRunner

  • Now to be on safer side repeat above step same for UnitTests, IntegrationTests_1, IntegrationTests_2, IntegrationTests_3 and IntegrationApp
  • Connect valid iPhone device to your Mac machine(Please ensure device is included in selected provisioning profile).
  • Select WebDriverAgentRunner under TARGETS and click on Test button to execute build on your connected device.

Figure-14: XCode: Test the Project on connected iPhone device

  • You can observe that when you click on Test/Run button the WebDriverAgent application will be installed to iOS device and it will open and give you the black screen for a moment and automatically closed. That means Success. Now you can able to Run Appium script on this device.(In fact it applies to all the valid devices registered under selected provisioning profile).

NOTE: Please install Appium-Doctor (Node Utility) using npm, It will  diagnose and fix common Node, iOS and Android configuration issues before starting Appium.

$ npm install -g appium-doctor
//then
$ appium-doctor
//it will give checklist of which things are okay and which are not
image of appium doctor node utility on IOS

Figure-15: Appium Doctor Node Utility on iOS

Installing Appium on Ubuntu(Linux)

Software required:

Install JAVA(JDK/JRE) & set JAVA_HOME

Install Java Development Kit Software from:

$ sudo apt-get update
$ sudo apt-get install default-jre
$ sudo apt-get install default-jdk
//to install oracle jdk
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

In order to set JAVA_HOME on linux you need to edit the .bashrc and need to specify the path of java directory.

$ vi ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=${PATH}:${JAVA_HOME}/bin
  • Run below command to verify that recently saved environment variables are displaying correct path or not.
$ echo $JAVA_HOME
$ echo $PATH

NOTE:  Use the command: $ which java to find out exact path to which java executable

Install Node.js without using sudo

  • Do not install node.js through apt-get, which will need sudo rights and appium will not work if node.js is installed as sudo user.

If you have already installed remove it using commands:

$ sudo apt-get remove nodejs
$ sudo apt-get remove npm
$ cd /usr/local tar --strip-components 1 -xzf /home/username/Downloads/node-v8.2.1-linux-x64.tar.gz
  • For Verification use below commands:
$ which node //it should give you output like: usr/local/bin/node
$ node -v  //it should give you output v8.2.1 (or whichever version you have installed)

Install Android Studio

$ cd android-studio/bin
$ . studio.sh //To execute the studi.sh script
  • Now android studio will open.Click next and let it download required things.
  • Once android sdk is installed add ANDROID_HOME to environment variable using:
$ vi /.bashrc
export ANDROID_HOME=/home/user_name/Android/Sdk

export PATH=$PATH:/home/user_name/Android/Sdk/tools

export PATH=$PATH:/home/user_name/Android/Sdk/platform-tools

Install Appium globally:

  • Open terminal and enter below commands in order to install the appium globally.
$ npm install -g appium
$ appium //To start the Appium server

Install appium-doctor to troubleshoot the errors if any using

  • Please install Appium-Doctor(Node Utility) using npm, It will  diagnose and fix common Node, iOS and Android configuration issues before starting Appium.
$ npm install -g appium-doctor
//then
$ appium-doctor
//it will give checklist of which things are okay & which aren’t
$ npm install -g appium-doctor 
//then $ appium-doctor 
//it will give checklist of which things are okay & which aren’t
desiredCapabilities.setCapability("xcodeOrgId", <<Team ID>>); 
desiredCapabilities.setCapability("xcodeSigningId", "iPhone Developer")

Appium eBook

Interested in Learning More?

Subscribe today to stay informed and get regular updates from Kobiton

Ready to accelerate delivery of
your mobile apps?

Request a Demo