Skip to main content

Create UIAutomator Project Using Eclipse

Step 1 : Open Eclipse IDE

Step 2 : Go to 'File' -> 'New' -> 'Java project'

Step 3 : Add Project name and click 'Next'

Step 4 : Click 'Finish'

Step 5 : Expand your project and right click on src folder -> 'New' -> 'Class'

Step 6 : Enter 'Name' for class . Also mention 'Package' and then click 'Finish'

Step 7 : Right click on your project -> open ' Properties'

Step 8 : Go to 'Java Build Path' 

Step 9 : Open 'Library Section'

Step 10 : Click on 'Add External Jar' and navigate to 'android-SDK/platforms' and choose uiautomator.jar and android.jar file

Step 11 : Click on ' Add Library ' -> Select 'JUnit ' . Select JUnit 3. If you want to select JUnit 4. Then you need Java 5.

Step 12 : Click 'Next' -> then 'Finish' . Then 'OK'

Step 13 : Writing Script for Mobicip safe browser application using UIAutomator function .

Example Code : 

package xxx.com.yyy.uiautomator.test;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.android.uiautomator.core.*;
public class OpenMonitorApp extends UiAutomatorTestCase 
{
public void launchApp() throws UiObjectNotFoundException,InterruptedException
{
getUiDevice().pressHome();
        UiObject appsButton = new UiObject(new UiSelector().description("Apps")) ;
        appsButton.clickAndWaitForNewWindow() ;
System.out.println("testcase execution completed");
        }
}

Step 14 : In terminal go to android-SDK/tools/ directory. Then Enter the following commands

./android create uitest-project -n name of project -t target devices -p pathofeclipseproject

// -n -> Name of the jar file
Ex: xxx ( without .jar )

// -t -> To generate a list of system image targets , use this command
In terminal, enter the following commands

./android list targets

After type above line, it's shown available system images target and you have to choose which target you want .

// -p -> Its your path of eclipse project
Ex : /home/gokulkarthik/workspace/xxx

Step 15 : export ANDRIOD_HOME=/home/username/android-sdk-linux

Step 16 : Go to Project Directory

Step 17 : Type in terminal ' ant build ' which command generates xxx.jar file in /bin folder

Step 18 : adb push jarfilelocation /data/local/tmp/ 
                                     or
                adb push jarfilelocation /sdcard/

// jarfilelocation -> workspace/projectname/bin/xxx.jar

Step 19 : adb shell uiautomator runtest xxxx.jar -c com.xxx.xxx.xxx.xxxx

// xxxx.jar -> Jar file name is enough. No need to enter the path for that Jar file. Becuase Jar file already pushed into the android system.

// -c -> Class

Ex : -c packagename.classname

        -c packagename.classname#methodname



Comments

Popular posts from this blog

Install and Configure Apache in Ubuntu 14.04

Easy way to install and configure "Apache" server in Ubuntu 14.04 1.Install apache:              sudo apt-get install apache2 2. In /etc/apache2/sites-available/000-default.conf :                 ScriptAlias /cgi-bin/ /var/cgi-bin/                <Directory "/var/cgi-bin">                         AllowOverride None                         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch                     ...

Linux Terminal Command

I will leave here some important basic linux terminal command that might be helpful during program installation and uninstallation process in Ubuntu. When you want to know the available version of package name then execute following command apt-cache policy packagename When you want to install the specific version of package name then execute the following command apt install packagename=version When you want to pin the package name not get to update in future then do the following In the following directory, /etc/apt/preferences.d/  Add the following content in the existing file, package : program name pin : version x.x.x* pin-priority : 1000  Note : pin-priority - This will prevent the program from the up-gradation. When you want to know the recently installed package name then execute the following command find /var/lib/dpkg/info/ -name \*.list -mtime -3 | sed 's#.list$##;s#.*/##' This will show the list package name which has ins...

PHP Session Clean

I was getting the following error when trying to browse the icingaweb2 website in the browser Fatal error: Uncaught ErrorException: Uncaught ErrorException: session_name(): Cannot change session name when session is active in /usr/share/php/Icinga/Web/Session/PhpSession.php:97 Stack trace: #0 [internal function]: Icinga\Application\ApplicationBootstrap->Icinga\Application\{closure}(2, 'session_name():...', '/usr/share/php/...', 97, Array) #1 /usr/share/php/Icinga/Web/Session/PhpSession.php(97): session_name('Icingaweb2') #2 /usr/share/php/Icinga/Web/Session/PhpSession.php(152): Icinga\Web\Session\PhpSession->open() #3 /usr/share/php/Icinga/Web/Controller/ActionController.php(540): Icinga\Web\Session\PhpSession->write() #4 /usr/share/php/Icinga/Web/Controller/ActionController.php(490): Icinga\Web\Controller\ActionController->shutdownSession() #5 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(512): Icinga\Web\Controller\ActionCont...