How to handle external application activity in android using robotium - android

I am trying to automate android app(Relocation services)using robotium. In this app there are media section and email and phone native dialer options so when i click on any of this option(Video, audio, phone, email) it takes you to the native app(video,audio, phone, email) of the phone. So how to handle external application activity using robotium(Like click on back button to come back to my app, or close native camera or video app to come back to my app)
Any answer will be great help.

You can only access your own app from within the instrumentation framework.
There are some options:
remove the default apps and add some fake apps to handle the intent (see https://github.com/bryanl/FakeCamera) for an example. to remove the app: http://oneclickandroid.blogspot.de/2009/01/how-to-remove-defaultpreloaded.html
resign the apps you want to control with your key so you can instrument them (see http://code.google.com/p/robotium/wiki/RobotiumForPreInstalledApps)
install your app with system permissions ( Android INJECT_EVENTS permission ), but haven't tried method yet

Sorry to bump this...
I've just put the camera stub and gallery stub that I made / use on the play store... thought might be of use to you / others for testing the camera and gallery in automated tests :)
https://play.google.com/store/apps/details?id=com.hitherejoe.CameraStub&hl=en
https://play.google.com/store/apps/details?id=com.hitherejoe.GalleryStub&hl=en_GB

I think, Using Robotium you can't access other application resources from your target testing application.
Just use Instrumentation for this,
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
But be sure if you are doing this in Activity then put this in separate thread for run this code..

Related

android applications interactions

I have a problem and a don't know how to solve it. I saw some tools for automation testing for android apps, like appium and others. They connect to the android device, emulator, from outside the device and open the application to be tested. I want to know how can i build a native android app that can to the same thing. Open another application and start executing different operations on the UI of that app. For a simple example, let's say i have a social app that i want to test. I want another that runs on the phone that opens my social app and starts running some operations like searching inside the app, clicking on different posts, liking post, s.o. Is there a way to do this? Are there any frameworks or methods for doing this?
Regards.
You have two kinds of automation frameworks for Android.
Instrumentation-based:
Robotium
Espresso
And black-box frameworks for functional testing:
Appium
Perfecto
ATMOSPHERE
The instrumentation frameworks work in the following way: As each android application runs in a sandbox and other applications can not change their behavior once they are installed, the instrumentation-based frameworks change the installation package of the application injecting hooks in the method definitions that allow them to interact with the application. This allows bypassing the sandbox in Android systems.
The other three all have UIAutomator Android service as basis for the interaction with the application. UIAutomator is part of hte Android SDK and allows emulation of real user interactions (e.g. click, scroll etc.), rahter than simulating them on lower, code level.
I believe that any of the five listed frameworks will allow you achieve what you want. I personally recommend black-box testing frameworks, as instrumentation can hide defects. My favorite framework is ATMOSPHERE - free to use, open sourced and although very recent a lot easier to use.
You would use an explicit intent to open a separate application.
public void openApplication(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i != null) {
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
} else {
Log.e(TAG, "Unable to start application");
return;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Package name not found");
return;
}
}
You would then call this method by providing the context and the package name of the application you want to open. For example, to open Instagram:
openApplication(this, "com.instagram.android");

Automation on Android Device

I am looking for a way to automatically open an application on Android. Something like QTP on windows. I read about quite a few testing tools for Android that need the phone to be connected to the laptop via USB. Is it possible to code an android application that can open another specific application on the device automatically?
I understand that if it is my application or an open source one, I can get the UI element and perform click or type into it automatically using code but how can I access UI elements of other apps on the device.
Example: My app should be able to open my phone keypad and type in a number or open an app like Truecaller and type into the textview on main screen? Something like web automation but for Android device. Any help would be appreciated! Thank you!
You can use Intents:
//consider context as being the Context of your current app
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(PACKAGE_NAME);
context.startActivity(intent);
device.wait(Until.hasObject(By.pkg(PACKAGE_NAME)), 10000); //this is a UiAutomator method to wait for the application to be started (or 10 seconds).
You can also use solo UiAutomator methods: open the apps menu, click on the app icon. You can see an example here

Opening an Android application within another

I am trying to open a different, already installed android application within another, on click of a button. The new application should be opened in a part of the screen within the calling application.
Currently, my code creates a new intent and runs the called application in that. the calling application disappears. Here's my code:
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.ritwik.camera");
startActivity(intent);
}
});
Ideally, it should open as a part of the same screen, without sidelining the parent(calling) application. How do I do that?
When you start an Intent to execute another application (i.e. because you are implementing a launcher or a main menu replacement) you are actually asking android to execute the application identified with a specific package (or the one satisfying some specific constraints, like the ability to handle images, videos, etc), without any clue or reference about the Activities it contains (nor the ability to get any...).
Therefore I don't think that what you are trying to achieve is possible with the current version of the OS (unless some vendor is providing extensions to do just that, see the comment by Pratik).
The new application should be opened in a part of the screen within the calling application.
This is not possible with conventional third-party application UIs.
AFAIK, the split-screen feature (Adaptive UI) is supported from Android 3.0 onwards.
That has nothing to do with embedding the UI of third-party apps into your own.
So I didn't get what you meant to say by "it's not possible with the current version of the OS"
It is not available on any stock version of Android released up through March 26, 2013 at 9:50am Eastern Time.
Certain device manufacturers, like Samsung, have extended Android with multi-window capabilities. However, the control over those windows lies with the user and the (modified) OS. Unless there is something in their S-Pen SDK for this, you have no way of starting another window.
Android also has RemoteViews, which is a means of passing a simplified UI between processes. Using this, it is possible for one app to embed RemoteViews published by another app. You see this with app widgets on the home screen, for example. However, both apps have to be written with this in mind, such as an app publishing an AppWidgetProvider to supply app widgets to home screens.
As far as I know, this is NOT possible. You can only launch the new activity, but you have no control of it.
EDIT: Some devices offer this possibility using Cornerstone or similar frameworks, but I haven't seen an option for developers to use this for their own apps.

Recording tool for tesing android applications

Is there any application that I can use to record user activity with android applications?
I want to get the user steps when they are testing the application. Is it possible to record their steps (maybe as screenshots)?
You could use the LogCat. At every step you want to record, print something to the LogCat
Log.D("Button Press", "User touched the 'View More' button);
And then using the LogCollectors source code (http://code.google.com/p/android-log-collector/
) you can email it to yourself and conduct your analysis.
Alternatively, you could try to use monkeyrunner (http://developer.android.com/tools/help/monkeyrunner_concepts.html) and create a script that runs and takes screen shots while the user uses the application [not sure if that would work - have never used it].
I would think for the purposes of collecting data, using the logcat would be a smoother and more detailed process.

Clear Flash Builder mobile application cache

I am building a Flex mobile application using Flash Builder 4.5, and testing it on a Samsung Galaxy 10.1 tab running Honeycomb.
I have integrated the AS3 Facebook library, but it won't let me log out, the session seems to stay behind, so once a user has logged in, they stay logged in until I have cleared the applications cache, or uninstalled and re-installed the application on the device.
What I would like to achieve here is to delete the cache folder for the application, or somehow clear the cache.
Any idea on how I can achieve this using AS3? Is there a better way of going about it?
Thank you.
Add the following event listener to you main application file applicationComplete or initialize event handler:
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, onDeactivateApp);
In onDeactivateApp function do the following:
protected function onDeactivateApp(event:Event):void
{
NativeApplication.nativeApplication.exit();
}
This should clear the cache, and the application will make you log back in when you restart it. This should be added to most mobile applications by the way.
Brian

Categories

Resources