signing and executing the test with Robotium Automation tool for Android Application
Automating apk
using Android Robotium for beginners
Once you are done
with the installation follow the below mentioned steps:
Note: Signature of
the application.apk and the signature of the test.apk should be same to
successfully execute the test.
First
of all verify the application.apk is signed or not, using the bellow command:
jarsigner
-verify -verbose -certs my ‘application.apk ‘
[Make sure that the
environment variable ‘Path’ is set with the value where you have kept the JDK
files. Else you will get an error ‘jarsigner is not a command]
If the command
returns "CN=Android Debug", this means the application.apk is not
signed.
If the command
returns "CN=any value other than Android Debug ", this means the
application.apk is signed.
To unsign the
application.apk
1. Change the
extension of the file from apk to zip. Unzip the content.
2. Delete the
META-INF folder.
3. Zip the content.
Again change the extension form zip to apk.
Now the apk is
unsigned. Verify it by executing the command “jarsigner -verify -verbose
-certs my ’Path\application.apk ‘”
Now, we have to
create a keystore to sign the apk.
Create a folder
D:\unsigned and execute the below command to create a key store:
D:\ unsigned
>"c:\Program Files\Java\jdk1.6.0_10\bin\keytool.exe" -genkey -v
-keystore donate.keystore -alias donate.keystore -keyalg RSA -validity 20000
This command will
create a keystore ‘donate.keystore ‘in D:\unsigned
Now Place the
unsigned apk in D:\unsigned folder and execute the below command to sign the
apk:
D:\ unsigned
>”c:\Program Files\Java\jdk1.6.0_10\bin\jarsigner.exe” -verbose
-keystore donate.keystore “D:\ unsigned \ application.apk” donate.keystore
The application is
signed now. To verify it by executing:
D:\ unsigned
>"c:\Program Files\Java\jdk1.6.0_10\bin\jarsigner.exe" -verify
“D:\ unsigned \application.apk"
The test we have
created has to be signed with the same signature as of the application.apk
Create an apk of
the test by following the below steps:
1. Go to
file->Export
2. From the Export
window select Android->Export Android Application
3. Select the test
project you have created and click on Next button. [This would be selected by
default]
4. In the kestore
selection window select ‘Use existing keystore’ radio button.
5. In the Location
edit box select the folder in which you have created the keysore [i.e.
D:\unsigned\ donate.keystore]
6. In the password
edit box enter the same password that you have used to create the keystore
7. Click on next
button and click on finish button at the end.
Now the test apk is
ready.
Now install both
the apks into the emulator using the below command:
C:\Program
Files\Android\android-sdk\platform-tools>adb install application.apk
It should return
success.
C:\Program
Files\Android\android-sdk\platform-tools>adb install test.apk
It should return
success.
At the end execute
the below mentioned command to execute your test
adb shell am
instrument ‐w com.collabera.test/android.test.InstrumentationTestRunner
Here ‘com.collabera.test’
is the package name of your test.
As a beginner we
make mistakes in updating the ‘AndroidManifest.xml’
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kalyan.sk"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="8"/>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.collabera.simplytravel" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
Here, the ‘Package’
variable should have the name of the test package you have created.
android:targetPackage
variable should have the package name of the application apk.
Regards
Kalyan
Comments
Post a Comment