How to locate Android Application elements using uiautomatorviewer in Ubuntu

UI Automator Viewer(UIautomatorviewer):
The user needs to Identifying Android application (AUT) objects for automating any android application using Appium. UIautomatorviewer such a GUI tool which provided by android SDK, to support automated, functional UI testing on android application. UIautomatorviewer provides a convenient visual interface for scanning and analyzing the UI components of an Android application. Users can inspect the UI of an android application in order to find out the hierarchy and view different properties (id, class,  text etc) of the element.

1. Connect your Android device with development machine(USB debugging mode should be enabled) or start emulator like Genymotion emulator
2. Open a terminal (Ctrl+Alt+T) and navigate to <android-sdk>/tools/
3. Run the tool with this command
./uiautomatorviewer
uiautomatorviewer window will show.
4. Open desired android application in your android phone or emulator
5. Click on the devices icon at the top right corner. It will start taking the UI XML snapshot of the screen currently opened in the device.
6. process to capture device screenshot.
7. After that, the snapshot of your device screen in the uiautomatorviewer window.
1. Left side: Android app's screenshot which is open in android device or emulator
2. Right side top part: Android app's UI element's hierarchy view
3. Right side bottom part: The property detail of selected element
8. Select button 9 to view it's different properties as shown in bellow image.

How to find Package Name And Launcher Activity Name from android APK file for Appium in Ubuntu

Android aapt stands for Android Asset Packaging Tool. This tool is part of the SDK (and build system) and allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.
Android Asset Packaging Tool installation:
Open terminal (Ctrl+Alt+T) and run the below command to install aapt
sudo apt-get install aapt

aapt is a generic Android asset package tool that be used as:
"aapt list" - Listing contents of a ZIP, JAR or APK file.
"aapt dump" - Dumping specific information from an APK file.
"aapt package" - Packaging Android resources.
"aapt remove" - Removing files from a ZIP, JAR or APK file.
"aapt add" - Adding files to a ZIP, JAR or APK file.
"aapt crunch" - Crunching PNG files.
Please go to below url and follow mention steps to download an android apk file from Google Play Store
https://hiromia.blogspot.com/2017/02/how-to-download-android-apk-file-from.html

Find Package Name And Launcher Activity Name from android APK file:
Command: aapt dump badging <path-to-apk>
Example Command: aapt dump badging /home/jannat/Downloads/com.andatsoft.myapk.fwa.apk
OR
Find Package Name:
Command: aapt dump badging <path-to-apk> | grep package:\ name
Example Command: aapt dump badging /home/jannat/Downloads/com.andatsoft.myapk.fwa.apk | grep package:\ name
Find Launcher Activity Name:
Command: aapt dump badging <path-to-apk> | grep launchable-activity:\ name
Example Command: aapt dump badging /home/jannat/Downloads/com.andatsoft.myapk.fwa.apk | grep launchable-activity:\ name

How to download an android apk file from Google Play Store and install it in Genymotion android emulator?.

You can download android apk file from Google play Store using browser plugin and website. In this tutorial, I am going show, how to download android apk file from Google Play Store using a website

Download an android apk file from Google Play Store:
1. Go to the Play Store and find the app you want to download and copy the app's URL address from the browser's address bar.

2. Browse to  website like http://apps.evozi.com/apk-downloader/

3. Paste the app package name or the whole Google Play URL  in the box at the top of the page then Click on 'Generate Download Link' button


4. Click download icon button to download apk file to PC

Install an android apk file  in Genymotion android emulator:
1. Start Genymotion android emulator and go to apk file  director where downloaded
2. Drag downloaded apk file, drop on Genymotion emulator screen

3. Wait few moment to install in Genymotion android emulator

4. Application home screen  shows after successfully installed





How to run Appium Android automation test with IntelliJ Idea and Genymotion emulator using java in ubuntu

Please visit the url for install & configure appium with IntelliJ Idea and Genymotion emulator in ubuntu

Install Genymotion plugin in IntelliJ Idea
File --> Settings : Select 'plugins' from left sidebar, Enter 'genymotion' in search input then install

Set Genymotion path



Create a Appium Java project in IntelliJ Idea
1. Open IntelliJ Idea, File --> New --> Project
Select 'Java' from left sidebar, Set jdk path and Click 'Next' button
Click 'Next' button
Enter Project name and set desired Project location which wants to save project, finally, Click 'Finish' button

Add Appium Java Client and Selenium Standalone Server jar as external libraries
File --> Project Structure : Select 'libraries' from left sidebar. Click '+' to add Appium Java Client and Selenium Standalone Server jar as external libraries

After starting Genymotion emulator, run 'adb devices' command in terminal to get Genymotion emulator deviceName

Run 'appium' command in terminal to start Appium and also get ip:portnumer

Demo java program for selendroid-test-app
 import io.appium.java_client.android.AndroidDriver;  
 import java.io.File;  
 import java.io.InterruptedIOException;  
 import java.net.MalformedURLException;  
 import java.net.URL;  
 import java.util.concurrent.TimeUnit;  
   
 import org.openqa.selenium.By;  
 import org.openqa.selenium.remote.CapabilityType;  
 import org.openqa.selenium.remote.DesiredCapabilities;  
   
   
   
 public class SimpleAppiumProgram {  
   
  private static AndroidDriver driver;  
   
   public static void main(String []arg) throws MalformedURLException, InterruptedException{  
   
       
     // apk file localtion  
     File appDir = new File("/home/jannat/apk");  
     File app = new File(appDir, "selendroid-test-app-0.17.0.apk");  
   
     //// Created object of DesiredCapabilities class.  
     DesiredCapabilities capabilities=new DesiredCapabilities();  
   
     // Set android deviceName desired capability. Set genymotion emulator name.  
     capabilities.setCapability("deviceName", "192.168.56.101:5555");  
   
      // Set android platformName desired capability. It's Android in our case here.  
     capabilities.setCapability("platformName", "Android");  
   
     // Set android VERSION desired capability. Set genymotion emulator OS version.  
     capabilities.setCapability(CapabilityType.VERSION, "6.0.0");  
   
     // Set BROWSER_NAME desired capability. It's Android in our case here.  
     capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");  
   
     //other caps  
     capabilities.setCapability("app", app.getAbsolutePath());      
     driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);  
   
     driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);  
     Thread.sleep(5000);  
   
   
     driver.findElement(By.id("io.selendroid.testapp:id/my_text_field")).sendKeys("Hiro Mia");  
   
     driver.findElement(By.id("io.selendroid.testapp:id/touchTest")).click();  
     driver.quit();  
   
   
   
   }  
 }  
   
   

How to install & configure appium with IntellIj Idea and Genymotion emulator in ubunutu

1. Required software
  • Oracle java JDK
  • IntelliJ Idea
  • nodeJS
  • Android sdk tools
  • Appium
  • Oracle Virtualbox
  • Genymotion
  • Selenium Standalone Server jar
  • Appium java client jar 
  • apk file
Latest Oracle java JDK install and configure in ubuntu
1. Add the PPA.
Open terminal (Ctrl+Alt+T) and run the below command:
sudo add-apt-repository ppa:webupd8team/java
2. Update system package index and install Java installer
sudo apt update; sudo apt install oracle-java8-installer
3. Check the Java version
javac -version
4. Set Java environment variables
The PPA also contains a package to automatically set Java environment variables, just run the command:
sudo apt install oracle-java8-set-default

Intellij idea download and install in ubuntu
1. Please watch the video for installing IntelliJ Idea

Latest version nodeJS install
First, choose the Node.js version you need and add the sources for it
# for Node.js v4
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
# OR for Node.js v5
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
# OR for Node.js v6
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# OR for Node.js v7
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -

Then install the Node.js package.
sudo apt-get install -y nodejs 

Android sdk tools download, update the latest API version and configure Android Home variable
2. update the latest API  
Create a folder name like 'sdk' in your desired location like 'Home' and extract downloaded sdk tools under sdk folder,  then Open terminal (Ctrl+Alt+T) and navigate to tools folder
Type below command for executable permission
sudo chmod a+x android
run the command to update desired API version
./android
Select desired API version then click on 'Install packages'
Note: It will take time to update

3. Configure Android Home variable
Run the command
nano ~/.bashrc

Add Android Home variable at the end of line 
export ANDROID_HOME=/home/jannat/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools


Save Android Home variable
Press: Ctrl+O  then Enter
Type 'android' command on terminal: Android SDK Manager shows if properly configured

Appium installation
Run the below command in terminal to get appium
sudo npm install -g appium  
Run the below command in terminal to get appium client
sudo npm install wd 
Run the below command in terminal to start appium       
appium 


Oracle Virtualbox download and install
Run the below command to install
sudo dpkg -i virtualbox-5.1_5.1.14-112924-Ubuntu-yakkety_amd64.deb

If missing packages when install, Run the below command
sudo apt-get install libpng16-16 libqt5core5a libqt5widgets5 libsdl1.2debian libqt5x11extras5 libsdl-ttf2.0-0 

OR Please watch the video for installing VirtualBox using command
 

Genymotion download and install
After login in Genymotion site  then click to download

Run the command to give executable permission
 sudo chmod a+x genymotion-2.8.1_x64.bin 
Run the command to install Genymotion
 sudo ./genymotion-2.8.1_x64.bin 

Please watch the video for more information