1. Install android studio :
https://developer.android.com/studio/
2. In Avd manager, install the required android os version and create the emulator.
3. Download appium :
http://appium.io/
4. Setup the environment variable in .bash_profile.
To set up :
i. Open the terminal
ii. Enter the command : open ~/.bash_profile
Set the environement variable like below:
export PATH=$PATH:/Users/premkumar/Library/Android/sdk
export ANDROID_HOME=/Users/premkumar/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/bin
iii. save the file and close it.
5. Install node js :
brew install node
6. Then install appium doctor :
npm install -g appium-doctor
7. Once it is installed, Run this command : appium-doctor --android
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 10.1.0
info AppiumDoctor ✔ ANDROID_HOME is set to: /Users/premkumar/Library/Android/sdk
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
info AppiumDoctor ✔ adb exists at: /Users/premkumar/Library/Android/sdk/platform-tools/adb
info AppiumDoctor ✔ android exists at: /Users/premkumar/Library/Android/sdk/tools/android
info AppiumDoctor ✔ emulator exists at: /Users/premkumar/Library/Android/sdk/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor
If all the things are set correct, then appium is configured properly in Mac.
8. run the program.
TO Launch Emulator in Command prompt in MAC:
${ANDROID_HOME}/emulator/emulator -avd Android
How to start appium server using Program:
Install Node Js:
https://nodejs.org/en/
Install appium:
npm install -g appium
Once the appium is installed use this method in your program to launch appium server:
private static AppiumDriverLocalService service=null;
public void startServer() {
service = AppiumDriverLocalService.buildDefaultService();
service.start();
}
To Stop Appium Server Use this method in your program:
public static void stopAppiumServer() throws Exception{
service.stop();}
To Launch Android Emulator use this method in your program :
public static void startAndroidEmulator() throws Exception{
Process p; if(System.getenv("ANDROID_HOME")==null)
p=Runtime.getRuntime().exec("/Users/premkumar/Library/Android/sdk/emulator/"
+"emulator -avd "+lib.getProperty("ANDROID_DEVICE_NAME"));
else
p=Runtime.getRuntime().exec(System.getenv("ANDROID_HOME")+"/emulator/"
+"emulator -avd "+lib.getProperty("ANDROID_DEVICE_NAME"));
Thread.sleep(10000);
}
To Close Android Emulator use this method in your program:
public static void stopAndroidEmulator() throws Exception{
Process p;
if(System.getenv("ANDROID_HOME")==null)
p=Runtime.getRuntime().exec("/Users/premkumar/Library/Android/sdk/platform-tools/
adb -e emu kill");
else
p=Runtime.getRuntime().exec(System.getenv("ANDROID_HOME")+"/platform-tools/
adb -e emu kill");
Thread.sleep(10000);}
To launch App use this method:
(Please make sure, I used lib.getProperty method to get value from the file , in that place use the value instead of method)
public static void AndroidappLauch() throws Exception {
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
lib.getProperty("ANDROID_DEVICE_NAME"));
capabilities.setCapability(MobileCapabilityType.APP,
System.getProperty("user.dir")+"/MobileApps/"+
lib.getProperty("ANDROID_APP"));
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
AndroidDriver driver=new AndroidDriver(new
URL(lib.getProperty("APPIUM_SERVER_URL")), capabilities);
framework.setAndroidDriver(driver);}