Showing posts with label Robotium. Show all posts
Showing posts with label Robotium. Show all posts

2013-05-18

How to press a key in Robotium?

In this article we are going to see how to press hardware keys of an Android device while performing Unit Testing using robotium framework.Now a days, most of the device do not have hardware keys. But, Android handles those keys separately than soft keys.

After Initiating solo, we need to use the object of solo.

 
-To press Up button
solo.sendKey(Solo.UP);

-To press Down
solo.sendKey(Solo.DOWN);

-To press Back button
solo.goBack();

-To press Right
solo.sendKey(Solo.RIGHT);

-To press Left
solo.sendKey(Solo.LEFT);

-To press Enter(Like pressing ok)
solo.sendKey(Solo.ENTER);

-To press Menu
solo.sendKey(Solo.MENU);

-To press Delete
solo.sendKey(Solo.DELETE);

Note ; All of them represents a integer value
RIGHT = 22
LEFT =21
UP=19
DOWN=20
ENTER=66
MENU=82
DELETE =67

If we integer value in place of that static code, it will work perfectly. Like in case of pressing UP
solo.sendKey(19);

Thanks...:) 

How to change alignment in Robotium?

In this article we are going to see how change the alignment of screen of an Android device while performing Uni Testing using robotium framework.

After Initiating solo, we need to use the object of solo. I will make a separate post for getting started with robotium development.

-To make the screen as landscape alignment.
solo.setActivityOrientation(Solo.LANDSCAPE);
Note : solo.LANDSCAPE is an static integer value which is Zero(0). So, if we write like this, it will work. 
solo.setActivityOrientation(0);

-To make the screen as portrait
solo.setActivityOrientation(Solo.PORTRAIT);
Note : solo.PORTRAITis an static integer value which is One(1). So, same function
solo.setActivityOrientation(1);

Thanks...:) 

2013-04-30

How to re-sign an android app(apk)?

In this article we are going to see how to un-sign a signed app. This is required when we will test an application apk file with robotium. For general ideal on robotium, I will provide separate post. First , let's have the apk file(application extension for a android app). Ex- game.apk

We can do this in two ways.

A. Manually :
Step 1:  Rename the APK as zip. Ex.game.zip

( To see the file extension in windows, Explorer > tools >folder option > view > un check )

Step 2: Delete META-INF folder
Step 3: Make the full folder into a ZIP file(re zip). Ex- game.zip

Step 4: Rename into apk extension. Ex- game.apk
Note(now there is no certificate now, so installation will be fail, if you try now) 
Step 5: open command prompt. and write the command
jarsigner -keystore [source keystore with path] -storepass android -keypass android [source apk with path] androiddebugkey
Example :  jarsigner -keystore C:\Users\shantonu/.android/debug.keystore -storepass android -keypass android D:\Android\android -sdk\platform-tools\game.apk androiddebugkey

Note : jarsigner  In windows PC, This command in here "C:\Program Files (x86)\Java\jdk1.6.0_06\bin" , so using command, you might need to brows to there.

Now you should be able to install apk.

Step 6: This is optional , it is necessary if apk is not installed properly. This will align the content inside the apk. To do this, From command prompt, navigate to \Android\android-sdk\tools, and type
zipalign 4   [source apk with path] [destination apk with path]
Example :
zipalign 4 D:\Android\android-sdk\platform-tools\game.apk D:\Android\android-sdk\platform-tools\AllignedApkName.apk

Now ,use that new apk and install to device.Your apk is re-signed with debugging key.

B. Using tool :
Step 1. Download the tool from this link
Step 2. Run this jar and drag the apk on to UI of the tool

Step 3: When it will prompt to save, save with new name


Step 4: press ok from confirmation message.


Now your apk is re-signed with debugging key.You may install in device.

Note : For windows pc, you need to add two system variable.
My computer > properties>Advance system settings >Environment variable
Then under system variables, press new

Variable Name : ANDROID_HOME
Variable Name : . Ex:- D:\Android\android-sdk\

Variable Name : JAVA_HOME
Variable Name : . Ex:- C:\Program Files (x86)\Java\jdk1.6.0_06\


Thanks...:)