Android programmatically automated touch events - android

I was wondering if there is any way to progam automated touch events? For example, I have my android app and I want to make a program where automatically make 100 tests and every test makes touch events depending on what appears on the app. And I would like to do this on emulators, if is possible all 100 test at the same time.

for exercising your app with many (more than 100 events) use monkey (Full name: UI/Application Exerciser Monkey) or/and monkeyrunner.
The Monkey is a command-line tool that you can run on any emulator
instance or on a device. It sends a pseudo-random stream of user
events into the system, which acts as a stress test on the application
software you are developing.
The Monkey includes a number of options, but they break down into four
primary categories:
Basic configuration options, such as setting the number of events to
attempt.
Operational constraints, such as restricting the test to a single package.
Event types and frequencies.
Debugging options.
Site: http://developer.android.com/intl/es/tools/help/monkey.html
Basic using:
$ adb shell monkey [options] <event-count>
Example
adb shell monkey -p your.package.name -v 500
So if you want to take control over Android system events and you're familiar with Python and writing testing scripts, then you can use monkeyrunner.
The monkeyrunner tool provides an API for writing programs that control an Android device or emulator from outside of Android code.
With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation.
The monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for running unit test suites, but you are free to use it for other purposes.
Documentation: http://developer.android.com/intl/es/tools/help/monkeyrunner_concepts.html
NOTE: The monkeyrunner tool is not related to the I/Application Exerciser Monkey, also known as the monkey tool. The monkey tool runs in an adb shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.

Related

Inject touch events android

I've been playing around with adb and adb shell input <some input> for the last few hours (building funny little batch scripts that can basically controll my phone.
Since I cannot execute these commands on the device itself without a PC with ADB and I don't want to root my phone I have been looking for an alternative on how to automate user input on the device.
I found a great Tutorial here, however it states that I need a system level permission in order to inject input events into other apps.
Again, I don't want to root my phone and I want the app to be compatible with different devices, so I can't sign it with the platform-key.
Beginning to think it was impossible, I remembered an app that could do such a thing. The anti virus app CM Security is capable of starting the chrome browser and clearing the browser data.
I assume this is done with input injection, but I am not sure about it.

Using an interactive shell with appium and python

I'm writing automated tests for our Android and iOS apps and I was wondering if there was an interactive shell in python for appium where you can run the app you are testing against and query the screen for certain elements. I know you can use 'arc' in ruby that let's you query the screen on the device for certain elements, but I can't find anything similar for python.

Genymotion scripting

Is it possible to create some kind of scripting with Genymotion?
I know there is shell commands, but I also need to simulate user touch (using adb input).
The idea is to create some simple test for my app, where the script will execute certain shell commands and adb as well.
Thanks
As Genymotion VMs are considered as a physical device by ADB, you can use MonkeyRunner.
This tool, provided by Google allows you to send touches events among other things.
You can script, using Python many inputs. Look at this gist, coming from this StackOverflow post, it gives good example for a complete gesture.

How will adbd and monkey runner affect the performance of the android device

I am doing some performance testing of the device and want to use the adb and monkey runner to automate andorid UI*. The concern is the background process would affect the actual performance of the device.
Questions are:
Through what mechanism does monkey runner work?
How much the performance* will be affected by the services of adb and monkeyrunner running on the device?
*sending command via adb to run monkey runner and pull the logcat.
*hardware performance: cpu mem power
The MonkeyRunner intro page has a good description of how MonkeyRunner works. Based on my personal experience using MonkeyRunner shouldn't impact your app's performance, however MonkeyRunner itself can sometimes be slow, so I wouldn't ever use MonkeyRunner to measure my app's performance.

Android debugging via Bluetooth

I was using earlier adb to debug Android applications over wifi, usb - it was great.
Right now I am wondering if it is possible to connect phone with adb via bluetooth.
I did a quick research but didn't find anything - have you tried it already ?
It is not supported by the current adb software, however you could probably make it possible if you have a rooted device (or possibly even if not - see below) either by modifying adb or by using bluetooth to tunnel a channel it does support, such as tcp.
You would need to obtain the source for the adb program - the same source is used to build both the PC and the device versions. First step is to just build it with unmodified functionality, which may take a fair amount of build system modification unless you do so as a part of a complete android source build (the way it was intended to be done)
Then you would modify it to add a bluetooth channel as an option and install it on the device (why you need root) and in your path on the PC. You'd think you could run it from an alternate location on the PC, and you likely can as long as you use it from the command line, but if your fire up DDMS it may kill off the running adb server and launch a new one using the default in the path, so ultimately you'll have to put your modified version there.
IF you can already get your device to accept adb connections over tcp (possible with root, perhaps possible in some cases without) there is another option, which is to not modify ADB (or at least not modify the device side) and instead come up with something running on the device which accepts bluetooth connections and forwards the traffic via local loopback to the tcp port on which the stock adb is operating. This would save the trouble of having to rebuild adb.
If you have some kind of tethering or similar network-over-bluetooth solution, you might even be able to leverage that to carry adb-over-tcp-over-bluetooth without writing any code.
Finally note that it is not 100% essential that the adb daemon run as a more privileged userid or be installed in place of the official one - you can run an adb daemon as an ordinary application and do many of the expected things with it. However, whichever adb daemon is running first will grab the unix domain java debug socket, and so only that adb daemon will be able to provide the full java debug services. More primitive things like logcat, shell, running process list, push/pull, etc will at least partially work without this, provided that your adb daemon doesn't quit (modification may be required) when it is unable to claim the debug socket. If you can kill the official adb daemon and exploit a race condition, you may be able to get an unofficial one started before it restarts - you would probably need to have a script or program to do this and run it with setsid from the official adb shell, meaning you'd need to connect via USB first. At that point, you'd also be able to start your unofficial adb daemon running as the same userid as the official one.
You may want to spend some time estimating or testing if the performance (speed) will be satisfactory before investing in a lot of time setting this up for real.
I know this is a bit old but I seem to have found a post that does this. All credit goes to the author of fomori.org for finding this and making the information available. Today it helped me, maybe tomorrow I'll help you by making it easier to find.
Source

Categories

Resources