Thursday, 11 April 2013

Adb command sequence to take picture and save it

there are list of ruby commands that can be used in calabash-android to get pciture from camera and save it

I had this problem running commands from calabash to take pciture, I was able to get past it using these 2 functions


def takePicFromCamera
   system('adb shell input keyevent 27') # click take picture button
end

  # save picture by clicking on save
  def savePicture
    system('adb shell input keyevent 21')
    Page.new.waitFor(2) # waitfor 2 second
    system('adb shell input keyevent 22') # select save
    Page.new.waitFor(2) # waitfor 2 second
    system('adb shell input keyevent 23') # Click save
    Page.new.waitFor(5) # waitfor 5 second
end

Sunday, 10 March 2013

Robotium testing webview example (test application and application) source download



Robotium test source code - https://github.com/tejasv02/Robotium4Webviewtest 
Webview sample test application - 
https://github.com/tejasv02/Androidwebviewsampleapp

 Robotium 4.0 has been released with webview support which enables testing of hybrid applications .
Some new functionalities have been added which enables testing of webpage embedded within native app also called as hybrid android application.
new functionalities inculde:
waitForWebElement(By by), clickOnWebElement(WebElement webElement), enterTextInWebElement(By by, String text), typeTextInWebElement(By by, String text), clearTextInWebElement(By by), getWebElement(By by, int index)

webview component is present in this file : https://github.com/tejasv02/Androidwebviewsampleapp/blob/master/src/com/myapp/WebViewActivity.java

customHtml  string is used to create a temporary html, which is used to fill 
webview and then this html is loaded into webview 

String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
webView.loadData(customHtml, "text/html", "UTF-8"); // if this line is commented , 
// uncomment it for test purpose


Tests are located in - https://github.com/tejasv02/Robotium4Webviewtest/blob/master/Robotium4webviewtest/src/com/testcalc/Testcase1.java


package com.testcalc;
import java.io.IOException;
import java.util.ArrayList;
import com.jayway.android.robotium.solo.By;
import android.view.View;
public class Testcase1 extends Apptest{
public Testcase1() throws ClassNotFoundException {
super();
}
public void testDisplayBlackBox() throws IOException {
Commonval.log(this.getName().toString());
solo.clickOnText("Go to");
solo.waitForWebElement(By.textContent("Hello, WebView"), 10, false);
solo.sleep(5000);
}
}


This is not an exhaustive explanation for a starter but should suffice some one who knows a bit of robotium,
Please feel free to leave comments below




Steps 

Part1: running webview application
Steps
1) Go to github copy project link - https://github.com/tejasv02/Androidwebviewsampleapp.git
2) Import project into eclipse
3) Solve dependency errors
4) Run web view application test as Android application

Part2: Testing webview application
Steps:
1) Go to github and copy project link - https://github.com/tejasv02/Robotium4Webviewtest.git
2) Import project into eclipse
3) Solve dependency errors
4) Run web view application test as Android application

Dependency
    Git plugin to download project from github -     http://download.eclipse.org/egit/updates
  
  
Problems : The import android cannot be resolved
    Install plugin for android - https://dl-ssl.google.com/android/eclipse/
    set path for Android SDK - Windows -> preferences -> Android


Video


 

Tuesday, 22 January 2013

Calabash Android Driver (Java)

Finally !!!
I did run calabash android to test mobile app with embedded webview using calabash
This tools covers all requirements necessary for mobile application testing project, there are some limitation as all functionalities are not implemented.

Certainly this is the best tool for mobile hybrid application testing (fonemonkey works fine but I am not very happy with that)

I have created a test project that can be downloaded and used to testing sample app, Just to make sure things are fine and installation is OK

Problems

1) when there is this below error
resign application using http://www.troido.de/re-sign.jar
java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{sh.calaba.android.test/sh.calaba.instrumentationbac
kend.CalabashInstrumentationTestRunner} from pid=549, uid=549 not allowed because package sh.calaba.android.test does not have a signature
 matching the target com.example.pickerviews2


2) When there are missing libraries search for them and add them to lib folder
Go to properties -> Java Build path -> libraries and remove Error libraries


3) Unable to resolve target 'android-7' PickerViews  Unknown Android Target Problem
This means project.properties will have  to be updated to android sdk level installed in SDK manager

Tuesday, 16 October 2012

Mobile testing tools latest update

I have been working in mobile testing close to 5 years and there are different tools that have gone past me.
Latetly I have used Robotium / Eggplant and tried Calabash / Fonemonkey(http://www.gorillalogic.com/) / Monkey runner and couple more.

Mobile Apps testing (not web related testing)
Robotium has given me pretty good results with testing of mobile apps, It can interact very well with apps and can be configured to run with Jenkins build server (other tools also can do that).
Its a very powerful open source tool and has been updated frequently so new functionalities are introduced and errors are correct pretty fast.

Mobile Web testing
Selenium Android driver and Selenium Iphone driver are the unchallenged masters for webtesting.The way Robotium works is pretty similar to selenium but the apps that can be tested is the real difference.
For anyone who has used selenium and has basic knowledge about testing mobile phones it must be a cake walk

Try gorilla logic if you want a record and play back solution 

Calabash is BDD focused tool and is available for both Android and Iphone , I have installed and tried it for learning purpose. haven't got it running for Real project.
I am pretty impressed with tool as such.

Eggplant is more of UI based tool and as per my experience its the only best tool available for Android / IOS / Symbian / Blackberry phones. There are loads of problems when it comes to connectivity but for limited set of repeated testcases it yeilds quick results. Sense talk used in Eggplant iss easy to learn.You definitely dont need to have programming knowledge to run the testcases.


Please leave compliments if like my blog or leave comments

(Selenium webdriver + Ant + Testng) Build.xml sample file to be used

I have got this build.xml from one of the sites...
and have customised it a bit to get it working.


${basedir} refers to project directory

I have updated path to suite.xml file in below code
I have also added below code to remove existing test output and create each one every time tests are run.

<target name="runTests" depends="compile"> <echo message="${basedir}"/>
<delete dir="${basedir}/test-output"/>
<mkdir dir="${basedir}/test-output"/> 
 <testng classpath="${test.classpath}:${build.dir}"> <xmlfileset dir="${basedir}/src/testpackage/" includes="suite1.xml"/> </testng> </target>

 

<
project name="Automation"
default="clean" basedir=".">
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="browser" value="/home/nxavier/Downloads/firefox/firefox"/>
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/" />
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<target name="loadTestNG" depends="setClassPath">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<mkdir dir="${build.dir}"/>
<tstamp>
<format property="timestamp" pattern="dd-MM-yyyy_(HH-mm-ss)"/>
</tstamp>
<property name="build.log.dir" location="${basedir}/buildlogs"/>
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean,init,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling.........."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" includeantruntime="false" classpath="${test.classpath}"/>
</target>
<target name="runTests" depends="compile">
<echo message="${basedir}"/>
<delete dir="${basedir}/test-output"/>
<mkdir dir="${basedir}/test-output"/>
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}/src/testpackage/" includes="suite1.xml"/>
</testng>
</target>
<target name="report" depends="runTests">
<delete dir="${basedir}/testng-xslt"/>
<mkdir dir="${basedir}/testng-xslt"/>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/src/xslt/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/>
<param expression="true" name="testNGXslt.sortTestCaseLinks"/>
<param expression="FAIL,SKIP,PASS,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
<param expression="true" name="testNgXslt.showRuntimeTotals"/>
<classpath refid="classpath_jars"/>
</xslt>
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'${basedir}/testng-xslt/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${basedir}/testng-xslt/Report.zip" basedir="${basedir}/testng-xslt"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build" ssl="false" user="tester@gmail.com" password="password">
<from address="tester@gmail.com"/>
<to address="tester@gmail.com"/>
<message>The build has finished. A details report of this build is aatched</message>
<attachments>
<fileset dir="testng-xslt">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target></
project>

Suite.xml must be written as per testng guidelines.
I haven't verified email functionality

I will make another post explaining how to use this build xml and run it from command line

Saturday, 6 October 2012

Selenium - Create CONFIG file and read it (java)

One of the challenges we face while creating test suite is to put common settings into a file and read it from code as and when neccessary. I did struggle a bit so thought sharing this might help any one who encounters similar problem.

Steps:

1) Create a file say in ur src folder or create a new package config and put a file called config.properties
2) From the file where you want to read create a varaiable like

public
static Properties CONFIG = new Properties();
3) Then load the content into it from the file you have created

FileInputStream fn = new
FileInputStream("path to project"+ \\src\\configure\\config.properties);

CONFIG
.load(fn);

4) Put a value into file config.properties which has to be read 
ex:
#url
mainsite=http://www.rediff.com

5) To read value from file
CONFIG
.getProperty("mainsite");
Some more system properties can be read from system as well
ex: System.getproperty("user.dir") for project


Wil share a sample code some time later but the above steps should help.

Friday, 5 October 2012

Resolving GIT problem in Eclipse



I installed GIT on my machine all of a sudden my eclipse was dead slow.
I had to over come this problem without unistalling git
After playing with preference found a solution atlast


Windows >Preferences -> Team -> GIT  and uncheck these boxes  as in the above picture