Appium : Sample Demo program of Android native app automation


import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;


public class AppiumDemo{

 protected static AppiumDriver driver = null;
 private static DesiredCapabilities capa = null;


 public static void main(String args[]){

  try{
   // Keep the .apk file in somewhere in your local directory , 
   // let's say D:\apkfile\facebook.apk 

   File app = new File("D:/apkfile/facebook.apk");
   //System.out.println("Path from where app is getting installed " + app);         

   capa = new DesiredCapabilities();    

   /*
    *  Appium Server capabilities/arguments
    */

   // Its a capability which lets Appium server know which 
   // automation you want to use Appium or Selendroid
   capa.setCapability("automationName","Appium"); 

   // Its a capability which lets Appium server know which
   // platform you to use Android or iOS
   capa.setCapability("platformName","Android");

   // Its a capability which lets Appium server know 
   // the device you are going to use
   capa.setCapability("deviceName","Samsung Galaxy S4");

   // lets Appium server know which device it has to connect and fire the commands.
   // Its optional when you are working only on one device including emulator or real device connected or running.
   // How to get the udid , please click here to know how to get udid
   capa.setCapability("udid", "XXXXXXXX");   // make sure to replace XXXXXX with original udid of your device

   // Its a capability which lets Appium server know the OS version of your device 
   capa.setCapability("platformVersion","5.1");

   // Its a capability which lets Appium server wait for a particular time before sending next command to device
   capa.setCapability("newCommandTimeout","30");

   // Its a capability which is used when you are dealing 
   // with sending Unicode chars as input to (UAT) app through Appium.
   // Again this is option capability if you are dealing only with EN input chars
   capa.setCapability("unicodeKeyboard", true);

   // Its a capability reset keyboard to its original state,
   // after running Unicode tests with unicodeKeyboard capability
   capa.setCapability("resetKeyboard", true);    

   // Its a capability which provide the absolute UAT application path or
   // you can also pass the remote path "http://xyx/fb.apk"
   capa.setCapability("app", app.getAbsolutePath());

   // lets Appium server know which Java package of the Android app you want to run
   // Using this package Apps are uniquely identified on the device
   // How to get the package name  , click here to know how to get package name
   capa.setCapability("appPackage", "com.facebook.katana"); 

   // Its a capability which lets Appium server know the Activity name for 
   // the Android activity you want to launch from your package
   // How to get the activity name  , Click here to know how to get Activity name
   capa.setCapability("appActivity", ".LauncherActivity");

   // Here are create the instance of Specific driver where it takes two parameter 
   // 1. Remote URL where the server is running and listening for the requests
   // 2. Passing the capabilities which we set above

   driver = new AndroidDriver(new URL("http://127.0.0.1/wd/hub"), capa);



  }catch(Exception e){

   System.out.println(e.getMessage());
  }
 }
}

No comments:

Post a Comment

Android : How to connect your Android device over Wifi using ADB command for App debugging

How to connect your Android device over Wi-Fi using ADB command Sometimes it requires to connect your Android dev...