Monday, November 19, 2012

Time to kick off android Instrumentation and monkeyrunner API


Recently I have updated Android SDK Tools 21.0 and came to know that they have added New UI Automation tool for App testers. This is was really cool and kick it off existing like android JUnit test case, monkeyrunner and Robotium APIs as well. This little baby code making more easy to write the test cases with less efforts. I am surely this APIs can be more matured over the next two years.

It is similar to robotium tool but having powerful APIs which it can wakup the device, crossing the package boundaries, rotating  and lock the screen orientation, taking screenshots.

As a test automation engineer, I was really interested on this. Google developers are making their OS more testable so I had high hopes with every release to see in this area. I just read the documentation and observed below good things and bad things

UI Automater

è  Good things
1.     Works across the Android OS System (NOT like package boundaries)
2.     NO connection for you app project (Does NOT require source code)
3.     JUnit based (familiar tool and test case structure)
4.     XML hierarchy dump tool in Monitor like DDMS/Hierarchy Viewer (Identifying the specific UI elements your test will need without the distractions)
5.     Useful and end up being maintained long-term (closely tied to the platform)
6.     Generates a JAR file which you can push in to the device or emulator
7.     Simple, readable, repeatable syntax and Able to crate the OR (Object repository like Q.T.P or Selenium)
8.     Updates and Bug fixes seem likely to be released infrequently

è  Bad things
1.     Still NO eclipse integration
2.     Still NO Native JUnit XML Reports
3.     Cannot be Downgraded (Only 4.1 or higher versions)
4.   WebViews still NOT supporting

Monday, July 23, 2012

Verify Android Device screen resolutions as with your Application Tests


This post can help you to verify the height and width of  Android Device Screen resolutions along with your application tests

public void testScreenResolution(){           
Context mContext = getInstrumentation().getContext().getApplicationContext();
// Here the Height of Screen expected value is 480
assertEquals(480,getScreenHeight(mContext));
// Here the Width of Screen expected value is 320
assertEquals(320,getScreenWidth(mContext));         
}

public static int getScreenWidth(Context context){
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
return display.getWidth();
      }
   
public static int getScreenHeight(Context context){
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
return display.getHeight();
}


Sunday, February 26, 2012

JInjector - J2ME Instrumentation testing


JInjector is an Instrumentation tool for Java Mobile Applications. 

J2ME applications consist of having a pair of files: the JAR and JAD. JAR file containing all the code and resources and JAD file is a text based containing execution parameters. The Deployment is J2ME applications as these tend to include code optimization and obfuscation, together with signing also.

Here the JInjector applies the Instrumentation and resulting classes are pre-verified and packaged together a specific device. But the Initial jar file should not obfuscated (or) optimized. The whole process and the testable code must be preverified again and The JAD descriptor file needs updating with the new JAR size. It instruments the system under test (SUT) in order to run automated tests in emulators and on the actual devices and It can also supports for code coverage.

Below the sample screenshot for the overall architecture



How to instrument LCDUI
LCDUI has strong has encapsulation and those classes cannot be instrumented. Because they are not part of the JDK. For Java Reflection They have done Java byte code conversion - a general purpose instrumentation tool based ASM

The Java ME code:
                        Form form=new Form();
                        form.addCommand(command1);
            Will be instrumented as
                        Form form=new FormWrapper()
                        Form.addCommand(Command1);

Here some of wrapper classes below
Alert- Alert wrapper, Canvas-Canvas Wrapper, Form – Form Wrapper, .. etc

And Wrapper classes have methods like as ……
getTitle();  getCommand(); getAllCommands(); commandListner(); .. etc

Simple test case using wrapper class methods
FormWrapper myForm = (FormWrapper) myScreen;
  assertEquals("The form title should be Sign in","Signin“,myForm.getTitle());
  Command c[]=myForm.getAllCommands();

A Test Method
Package com.reddyapp.test.auth.register;
import com.reddyapp.j2me.JInTestCase;
public class TestHelloMIDlet extends J2meTestCase {
                        public void testRegisterForm (){
                        }
}

Test case Asserts
public void testRegisterForm (){
assertEquals("The form title should be Reddy, “Reddy“, mainForm.getTitle());
}

Test Reporting and Test Results



Sunday, February 12, 2012

Test your mobile web application with MITE (Mobile Internet Testing Environment)

I hope this post can help you to how to present and test your web application accessing through into different devices.

Now a day’s People are spending more time on mobile devices and Tablet P.Cs than to traditional computers. Web Sites must be providing an excellent experience to visitors using one of many thousands of mobile devices. We may expect traffic in the thousands of users every day.

So Development and QA team has to take care of their web pages to present, test and verify that content is correctly formatted & displaying across mobile devices. In these areas you need to be test each and every screen with HTML elements (attributes, content, Styles), Local storage (Offline storage & online storage), cookies and application cache.

Here is some of the useful information about How to launch and view the web page content


Launch the GoMO

Take the URL of your Test web page and paste it in there. You can see your desktop site on a mobile phone. It can help you to improve the customer or User web view experience

The mobile Web view results will be displayed as per below


MITE comes with a script recorder that lets you capture each step as you navigate a mobile website and also you can be able to test many devices at time

Here are some open source tools for I Phone Browser test and debugging for your I phone web application

I Phone Browser testing:  iwebinspector

Cross verify your mobile web features with below link
HTML5 compatibility on mobile and tablet browsers: Web features Cross verification


Friday, November 25, 2011

Droid Explorer - Android Stuff into One place


Droid Explorer is a open source & completely free app for your Desktop computer.
It can help you to get the screenshot, video recording logs & system files from your android rooted phone. But it needs the android SDK installed in your computer.

Please find the followed link for to get this app

Wednesday, September 21, 2011

Android testing with Maven build management


This post may be can help you to quick start for android testing as with maven


As we know Maven can build the android projects + runs the Instrumentation tests. Like Building, Deploying, Testing and Advanced level reporting.. And also having a very good folder structure to keep all the source test classes and run into the several devices

Using by maven you easily maintain extensive unit tests and your activity tests, service tests, content providers tests and all in to one place...


A sample Maven Android Test Directory 


..app> mvn install

When you run this target, Firstly it can compile the all the source class files Secondly, it  can run only the unit test cases  and generate the reports.

..app-Instrumentation> mvn install
This target compiles the automation test cases and generates the test .apk file

Robotium using by Maven  
You can also write automation UI test cases by using Robotium for automation testing. There is no need to attach Robotium jar file. This jar file will take from repositories itself. All the dependencies will automatically download. You can also execute same test suite in to the number of devices also.

Advantages :
1. Run the test cases by using single command from the command prompt
2. Multiple device support for test execution
3. Automatically generate the test reports in the XML format for each and every device which are connected
4. No need to worry about signature(signing) 

Dis Advantages:
1. The build system can depend on the source code. So without application source code it is not possible to run your automation test cases... 

For use to get robotium in your test project , You need to add the followed dependency  


Test Suite building

import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests extends TestSuite {
    public static Test suite() {
        return new TestSuiteBuilder(AllTests.class) .includeAllPackagesUnderHere() .build();
      }}

Running tests

If you use a test runner other than InstrumentationTestRunner, you must change the element to point to the class you want to use.

instrumentation android:name="android.test.InstrumentationTestRunner"
                       android:targetPackage="com.pkg_name "

Once the Instrumentation starts, android system classes can load and start the test package, If any other processes are running it can kill all the processes and run an instance of the application under test, and then it can load a new instance of the application under test.

…app-Instrumentation> mvn android:deploy 
This target can run the Instrumentation can start and can run with the device or emulator 

Multiple device support for deploying and getting the test results for Test reporting 

If you run a test in Eclipse with ADT, the results are displayed in a new JUnit view pane only and again at end of the test, you have to export the results in to the XML files…

So it is very hard to run and saving the reports. and also time consuming

In this case maven can the run unit tests and instrumentation tests in the number of devices and finally it can generate the reports into the XML files and save the reports for each device or emulator


A sample automation report generated by Maven run time environment



In this case I have attached one real LG Android device, 2 emulators and the XML file reports has generated with prefix name as a “TEST-……..”

You can also give the name of the devices to only run all emulators or only all devices or only a specific device
mvn android:deploy -Dandroid.device=emulator-5554
mvn android:deploy -Dandroid.device=emulator-5556
mvn android:deploy -Dandroid.device=someAvdName
mvn android:deploy -Dandroid.device=8283838993839393AESA
mvn android:deploy -Dandroid.device=deviceSerialNumber 


Followed links may be help you to get know more details about this 


Sunday, September 18, 2011

Maven Android Plugin 3.0


Maven build system for Java project management

       This post can give to you a brief introduction about maven build system and also how to setup the development environment.

       So what is Maven ?  Maven is a Java project management and integration build tool. Similar to like Ant build tool. It can work based on the concepts of Project Object Model (POM ) xml file. It  can helps you to generate the reports and so many.Maven intelligence is it can talks to the repositories which are available in online and it can gets that information..that is the beauty of Maven build system

       Maven having a very good project structure for to keep multiple directories and multiple jar files.  If your project is using multiple jars or frameworks, so maven can helps you to pick the all jar files into one place and can deploy it. In order to compile or deploy an application, you may need to take all the jar files. Sometimes some jar files also can dependent on other jar files and jar versions so that point of time it can be help you lot. 

We need to setup environment variables for to run maven build commands like as below:
MVN_HOME = D:\Apps\apache-maven-3.0.3;
Path = %MVN_HOME

1.    Get to know the version of maven
              >>mvn  --version
It can show the maven home variable, java location and along with the OS information…

Apache Maven 3.0.3 (r1075438; 2011-02-28 09:31:09-0800)
Maven home: D:\Apps\apache-maven-3.0.3\bin\..
Java version: 1.6.0_17, vendor: Sun Microsystems Inc.
Java home: D:\Apps\java\jdk\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windo

      2. Maven Project creation step by step:

      archtype:generate command can create a new maven project with directory structure. 
While executing this command it may ask few options to setup the build system for the pom.xml

>>mvn archtype:generate
>> It can download all the repositories which are available from online through internet connection and also it can ask few options for user to creation of project
1.       Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co
ntains): 130:
>> choose a different architect model  number which are available
2.       Choose version:
Choose a number:
>> Enter maven version number
3.       Define value for property 'groupId': :
>>Enter your group ID like: org.obulreddy
4.       Define value for property 'artifactId': :
>>Enter your  application  name: AndroidTesting
5.       Define value for property 'version':  1.0-SNAPSHOT: :
>> Enter version value
6.       Confirm properties configuration:
groupId: org.com.obulreddy
artifactId: AndroidTesting
version: 1.0-SNAPSHOT
package: org.com.obulreddy
 Y: :
>> Enter confirm prosperities configuration say yes “Y” or no “N”
Finally it can create a directory called “AndroidTesting”, which you have given for artifact ID and also pom.xml

Android Project build system by using Maven plugin 3.0

       There are Lot of advantages for Android development, automation testing, test reporting using maven android plugin
       And also easy and quick way to start the multiple emulators for installing the .apk file through targets  from the command prompt
       To get Android build system  to work with Maven, you need to do a couple of extra things…
      Like preparing to set up android SDK and Maven system variables
       ANDROID_HOME = “ ….SDK  directory….”
       MAVEN_HOME = “….Maven directory….”

Followed steps can help you to quick setup for then android maven plugin 

1.       Create a project from command prompt
               >>  android create project --target 1 
                      --name MyAndroidApp
                      --path ./MyAndroidAppProject 
                      -- activity MyAndroidAppActivity
                      --package  com.example.myandroid                                                               

2.       To use Maven, You have to remove unnecessary files - build.xml, build.properties, libs
              >>  del build.xml build.properties libs

3.       Create a pom.xml file and give the values of groupID, artifactID, and name


Set the Android SDK version properties, api level version and emulator information in the build target


4.       >>mvn install
It can take a while time to download Maven repositories from the Internet
Finally it can show the Build successful message and also memory as well
In this step, unit tests will also be done from the “test” folder. But now in this case there are no unit tests. So that it can give test runs as  “0” like as below


5.       >>mvn android:deploy
             This target can try to install your .apk file in to the connected device
              And gives the successful installation message along with .apk file directory and device or emulator 



          You could use directly for the build application like as followed
          >> mvn install android:deploy or mvn clean install android:deploy

The code for the example application is available as part of the maven-android-plugin-samples available at

Friday, September 9, 2011

New selenium 2.0 ! ( WebDriver + selenium )

Now Selenium has integrated with webdriver and released with named as a Selenium 2.0 which can offering more object oriented testing and not depending on any server setup like selenium RC.

             It's not tying to any particular test framework, it can be used equally well with JUnit, TestNG or from a plain old "main" method also...

             It can acts just as a normal Java library does: it's entirely self-contained, and you don't need to remember to start any additional processes or run any installers before using it…

             Through WebDriver you only need to pick a driver like called as a Chrome, IE, Fire Fox, iOS, android driver and create a test without any dependencies of a server.this functionality can works using dynamic proxies.It has taken a different approach to solve the problems like where selenium struggling with browsers rather than being a JavaScript application running with in the browser, it uses whichever mechanism is to control the browser.

Earlier selenium test setup setting was like as below:

-          By Using Selenium RC and the proxy settings

                        Selenium selenium = new DefaultSelenium( "localhost", 4444, "*firefox", "http://www.google.com");
                        selenium.start();
                        selenium.type("name", "text");

      After integrating with the webdriver replaced that code as below:

                        WebDriver driver = new FirefoxDriver();
                        driver.get("http://www.google.com");
                        WebElement searchBox = driver.findElement(By.name("q"));
                        searchBox.sendKeys("selenium");

            Once your project is set up, you can see that WebDriver acts just as any normal library..that means that you shouldn't expect a WebElement to be a particular subclass, even if you know the type of the driver.. It can step outside the Java Scripting and much more object oriented testing capabilitie...

             One of main future  which I can like “Page object”. Page Objects are objects within the test code it self... it can reduces the amount of duplicated code and means that even if the UI changes, the fix need only be applied in one place ...