How to setup Appium on Mac OS to run automated tests from JAVA classes on Android and iOS devices

96,037

Solution 1

Answered by Igor Vishnevskiy I have been looking for the answer everywhere on the internet and could not find anything. It took me some time to make this work. I hope this quick guide will help the next engineer to save some time on setting up Appium to run automation on Android devices. Appium will not run if NODE or Appium itself is installed using SUDO and MAC won't let you install neither without using SUDO. There is a workaround though. My steps make it possible to install and setup Appium the right way without need to use SUDO for installation. Everything is tested and it works. Below are the steps. Enjoy!

There could be one problem while setting up Appium using bellow steps. If you face some errors while creating or saving data into certain directories, that is caused by the luck of write permissions set to those directories. What you will need to do is to set CHMOD to 777 to the directories where components of Appium are trying to write while installing and then rerun all steps again.

Step 1: Install JAVA 6. You will need JAVA 6 with Appium. JAVA 6 for Mac OS has to be downloaded from Apple's support page: http://support.apple.com/kb/DL1572

Step 2: In your bash add the following path using following format:

export PATH=$HOME/local/bin:$PATH

Step 3: Setup Maven (Download and set Bash profile PATH for Maven):

http://maven.apache.org/download.cgi

------> This is what your Bash Profile should look like:

export PATH="/Users/your_username/Desktop/adt-bundle-mac-x86_64-20140702/sdk/platform-tools":$PATH
export PATH="/Users/your_username/Desktop/adt-bundle-mac-x86_64-20140702/sdk/tools":$PATH
export PATH=$HOME/local/bin:$PATH
export ANDROID_HOME=/Users/your_username/Desktop/adt-bundle-mac-x86_64-20140321/sdk
export PATH="/Users/your_username/Desktop/apache-maven-3.2.2/bin":$PATH
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)

Obviously to run tests on Android device, you will need to download Android SDK and add it to your Bash Profile as well. To run tests on iOS devices, you will only need to install XCode, no need to add that to your Bash profile. But Android SDK has to be added.

Step 4: Copy and paste following sequence of commands into your Terminal window and press ENTER. Copy and pasting it all together will work. It will take some time to install NODE, so be patient.

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install

Step 5: After installation from Step 4 is complete, run following command in your Terminal window:

curl https://www.npmjs.com/install.sh | sh

Step 6: Then in your Terminal window execute following command:

npm install -g grunt-cli

Step 7: Then in your Terminal window execute following command:

npm install -g appium

Step 8: Then in your Terminal window execute following command:

npm install wd

Step 9: Then in your Terminal window execute following command to start the Appium server:

appium &

(step 9 will start the server).

Step 10: From the separate terminal Window cd to root directory of your JAVA project in your workspace. (example: cd /Users/ivishnevskiy/Documents/workspace/ApiumJUnit)

Step 11: Attach your Android device to USB and to your MAC computer.

Step 12: In the same Terminal window from Step 10, run following command to launch the Appium test:

mvn -Dtest=test.java.com.saucelabs.appium.AndroidContactsTest test

where test.java.com.saucelabs.appium is a package name and AndroidContactsTest is a class name.

If you still need help setting it up. Let me know. I can help. My LinkedIn: http://www.linkedin.com/pub/igor-vishnevskiy/86/51a/b65/

AFTER SETTING APPIUM UP ON YOUR DEVICE, FOLLOW MY NEXT TUTORIAL TO CREATE IN ECLIPSE AND RUN YOUR FIRST TEST ON THE ACTUAL iOS DEVICE (NOT EMULATOR): https://stackoverflow.com/questions/24919159/

Solution 2

I used this post to help me set up Appium on my Mac. I also used other sources to do my installation completely. Here are step by step instructions to upgrade to appium 1.7.x seamlessly on your Mac OS X.

Please make a note of the following details BEFORE you start the upgrade process

  • If Appium is not installed on your system previously, please use ONLY the commands related to "Install" below
  • If you face any problem of deleting folder/directories using command line, please go to Finder and delete it
  • Once you upgrade to new OS on your Mac machine, App Store and iTunes may open late and work slow for the first time

Step by Step Instructions

  1. Need to install OS 10.12.x or higher version.

  2. Need to install Xcode 9.x. Sign in with your developer account (https://developer.apple.com/download/more/) and download it OR Download it free from the Mac App store

Note - If you face problems while installing the new version of Xcode then please uninstall the old versions.

  1. Need to install the Command line tools for Xcode 9.x.

Launch Terminal and enter the below command

xcode-select --install
  1. Uninstall HomeBrew

Uninstall Command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
  1. Install HomeBrew

Install Command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Uninstall all instances of Node

    • go to /usr/local/lib and delete any node and node_modules

    • go to /usr/local/include and delete any node and node_modules directory if you installed with brew install node, then run brew uninstall node in your terminal

    • check your Home directory for any local or lib or include folders, and delete any node or node_modules from there. (To reach home directory open Terminal and enter cd)

    • go to /usr/local/bin and delete any node executable

  2. Install Node

Command:

brew install node
  1. Install ideviceinstaller:

Command:

brew install ideviceinstaller
  1. Uninstall Appium from terminal

Command:

npm uninstall -g appium
npm cache clean --force
  1. Install Appium

Command:

npm install -g [email protected]** (Or we can just do npm install -g appium)
  1. Need to Install supporting tools for Appium 1.7.2

Command:

brew install carthage
npm install -g ios-deploy
npm install -g deviceconsole
  1. For downloading simulators go to Xcode --> Preferences --> Components, and download necessary simulators.
Share:
96,037

Related videos on Youtube

Igor Vishnevskiy
Author by

Igor Vishnevskiy

Updated on July 05, 2022

Comments

  • Igor Vishnevskiy
    Igor Vishnevskiy almost 2 years

    Problem I was facing with Appium that I decided myself below. I could not find a way to install required components for Appium without using SUDO. After installing it all with SUDO, then trying to run Appium, I was getting error that Appium and NODE should have been installed without SUDO. Trying to search online for solution took me quite a while since there are almost no tutorials exist online for Appium to run on MAC while developing tests using JAVA. Below is the step by step instruction on how to set up Appium on Mac OS and run a first test from within a Java Class. Just copy and paste commands into Terminal on your Mac and you will set it up. I wish there were more clear step by step tutorials online for Appium. Tutorials written by developers of Appium are so vague, I don't even want to recommend to look for answers on their website.

  • HRVHackers
    HRVHackers over 9 years
    Great write up. I'd also add this step to upgrade to latest version: npm install -g appium
  • Emjey
    Emjey almost 7 years
    You can install appium any time you want to, it is just that it would need prerequisites to run. All the things that is mentioned inside the bash_profile
  • Elmue
    Elmue almost 5 years
    It seems you copied this article: swtestacademy.com/how-to-install-appium-on-mac but left away all the usefull images. I cannot see where you install XCode. Did you really ever test these steps or just copied them from another page?
  • Shiv Shankar Balaji
    Shiv Shankar Balaji almost 5 years
    - All above steps are done by own and posted in my own blog dated on 08/2018. - techsouljours.blogspot.com/2018/08/install-appium-on-mac.htm‌​l - Xcode can be installed by using app store - From swtestacademy posted date on By Onur Baskirt|March 16th, 2019 @Elmue