Appium : How to get the UDID of Android Device

How to find the UDID of Android Device

What is UDID :

It stands for Unique Device Identifier.
UDID is required during Android application development or Android App automation to get the unique id of the Android device. It is needed in cases when the user wants to track the unique device installations of the application or to send the ADB commands to the device while executing automation scripts.

To find UDID of Android device

You can watch Youtube video or follow the step by step procedure below:

 

                                                    OR 

Step by step procedure below:

1.
Go to settings for your Mobile device -> About Phone -> Build Number -> Tap 7 times to enable Developer options.

2.
Go to Developer options , under Debugging -> Make sure to enable USB debugging ON.

3.
Now connect your mobile device(using usb cable) to your PC.

4.
Open Command Prompt and type below command
   -> adb devices

*(Make sure ADB configured in your path variable, click here to know how to configure adb)

5.
Note down the UDID of your device.

6.
It will appear as shown in below screenshot


How to get the UDID of Android Device




Thank You!!

Appium : Setting up the environment for Android automation


To setup Appium for mobile automation, you will need below items to be configured in your test environment.

1. Appium server :

 1.1 Download Appium server from official site
 1.2 After installation , Appium server UI














2. Android SDK & ANDROID_HOME Configuration:

   2.1 Download Android sdk from official site
   2.2 Now configure the ANDROID_HOME
















2.3 Select "path" and click edit button,
2.4 Add below two parameters
        %ANDROID_HOME%\tools;
       %ANDROID_HOME%\platform-tools
2.5 To check if ANDROID_HOME configured properly or not, open command prompt and type
    adb











3. Java JDK & JAVA_HOME Configuration:

    3.1 Download Java jdk from official site
    3.2 Install the jdk on your test machine where you want to setup the environment
    3.3 Now configure the JAVA_HOME























You can see the JAVA_HOME configuration in below video:



Thank you!!

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());
  }
 }
}

Selenium WebDriver : How to find the highlighed text on webpage.





/*
* How to find the highlighed text on webpage.
* Programming language : JAVA
*
* We can achieve this with the help og JavaScript indow.getSelection().toString() function
*
*/
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;



public class HighlightedTextOnWebPage {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = null;

driver.get("https://google.com");
Thread.sleep(5000);
// Try to highlight any text on webpage using the mouse.


if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
}

String hldText = (String)js.executeScript("return window.getSelection().toString();");
System.out.println("Highlighted Text on WebPage is : " + hldText.trim());

}
}

Selenium WebDriver : How to handle PopUp and close it


/*
* Pop-up handling in Selenium WebDriver
* Programming language : JAVA
*
* Here we will browse Rediff site and close the pop-up .
* We will print the pop-up window URL and the main window URL
*/

import java.util.Iterator;
import java.util.Set;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PopUpHandling {

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

// for chrome browser setting
//System.setProperty("webdriver.chrome.driver", "D:/setup/chromedriver.exe");
//WebDriver driver = new ChromeDriver();

driver.get("http://www.rediff.com/");

// Since the Window Handles are unique , we will use java.util.Set to store as it does allow the duplicate values.
// Windows Handles is of type String, so we store the value of window handle as String in Set
Set<String> winHandle = driver.getWindowHandles();

// just to check the number of total windows , in this case its 2
System.out.println("Total number of Windows : "+ winHandle.size());

// Iterator is use to iterator through Set , we can use for loop also
Iterator<String> it = winHandle.iterator();

String parentWindow = it.next();


String childWindow = it.next();

// switch to child window / pop-up window
driver.switchTo().window(childWindow);

System.out.println("child URL/ Title : " + driver.getCurrentUrl() );
driver.close(); // close the child /popUp window

driver.switchTo().window(parentWindow);
System.out.println("parent URL/ Title : " + driver.getCurrentUrl() );

}

}

Selenium WebDriver : Example to set and invoke different browsers through WebDriver


/*
* Example to set and invoke different browser in Selenium WebDriver
* Programming Language : JAVA
*/
import java.util.Scanner;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class SettingDifferentBrowserinSelenium {

static WebDriver wd = null;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter browser which you want to invoke : ");
String browserName = sc.next();
openBrowser(browserName);

}


public static void openBrowser(String browserName){

if(browserName.equalsIgnoreCase("Mozilla")){
wd = new FirefoxDriver();
System.out.println("Browser invoked : " +browserName);

}else if(browserName.equalsIgnoreCase("Chrome")){

//for chrome browser you have to set the path
System.setProperty("webdriver.chrome.driver", "/path_to_chormedriver/chromedriver.exe"); // D:/setup/chromedriver.exe
wd = new ChromeDriver();
System.out.println("Browser invoked : " +browserName);

}else if(browserName.equalsIgnoreCase("Chrome")){

//for ie browser you have to set the path , use the IEDriverServer.exe based on your OS architecture x64bit or x86bit
System.setProperty("webdriver.ie.driver", "/path_to_iedriver/IEDriverServer.exe"); // D:/setup/IEDriverServer.exe
wd = new InternetExplorerDriver();
System.out.println("Browser invoked : " +browserName);

}else{

System.out.println("You can either invoke the default browser or display"
+ " a message to provide valid broswer name ");
}

}

}

Java : Program to find the minimum and maximum number in a given array.


/**
* Find the minimum and maximum number in a given array.
*
* Approach: we can pick an element from array and compare with the min and max value
*
*
*/

public class MinMaxNumber {

public static void main(String[] args) {

int arr[] = {1100,10,3,5,8,1,5,9,23,56,0,90,54};
int min,max;
min=max= arr[0];
for(int i =1 ; i<arr.length;i++){

if (min > arr[i]){ // comparing the number for min value
min= arr[i];
}

if(max < arr[i]){ // comparing the number for max value
max=arr[i];
}
}
System.out.println("Min value = " + min);
System.out.println("Max value = " + max);

}

}

/* output
Min value = 0
Max value = 1100

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...