Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 598
Igor Vishnevskiy Avatar asked Jul 17 '14 21:07

Igor Vishnevskiy


People also ask

Can we run Android automation test in Mac machine using Appium?

Setup Appium on Mac OS for Android and iOS App Automation [2022 Update] Appium is an open-source test automation framework for use with native, hybrid, and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.

Can we automate Android on Mac?

If you want to automate Android devices via a Mac, you have to install Android SDK Tools on your Mac. To do so, install Android Studio. For more information, go to the official Android Studio web page. Alternatively, you can install the stand-alone Android SDK Tools.

Does Appium support cross-platform testing?

Appium allows native, hybrid and web application testing and supports automation test on physical devices as well as an emulator or simulator both. It offers cross-platform mobile Apps testing, i.e. a single API works for both Android and iOS platform test scripts using the WebDriver protocol.

Which is the protocol used by Appium to run iOS and Android sessions?

Similar to the case of Android devices, Appium uses the JSON wire protocol for iOS devices as well. Here, it uses Apple's UIAutomation API to interact with the user interface elements for automated iOS device testing.


2 Answers

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/

like image 95
Igor Vishnevskiy Avatar answered Oct 22 '22 04:10

Igor Vishnevskiy


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.
like image 20
Raj Subrameyer Avatar answered Oct 22 '22 05:10

Raj Subrameyer