I have a Jenkins job that starts a Robotium test from command line:
adb shell am instrument -w com.foo.tests/android.test.InstrumentationTestRunner
Sometimes the test run gets stuck. When I abort the Jenkins job, it does not stop the Robotium test run. I may have to cancel the test execution manually from the device before running another Jenkins job.
How do I stop the test execution? I cannot just uninstall the application under test with adb uninstall since it has active device admin.
You can cancel the previous Robotium test by starting another test one with a made-up test name:
adb shell am instrument -e class com.foo.tests#dummyTestName com.foo.tests/android.test.InstrumentationTestRunner
What about this:
adb shell am force-stop <PACKAGE>
You can clear the app data,like this
adb shell pm clear com.foo.tests
Related
I try to develop script to launch armeabi-v7a emulator and execute gradle connectedAndroidTest task to run android device tests targeted to my app.
I wrote script which successfully check required emulator target and download and install it if it is missed and then launch emulator. All these points work well. But After I launch emulator I have to wait until it will be completely booted.
I guess my problem is that I cannot rightful detect that emulator was completely finish his boot operation and is ready to install apps as well.
According to suggestions in web we can use two following system properties to detect complete boot, it is
init.svc.bootanim - state of boot animation
sys.boot_completed - system state of boot operation
We can revise them by calling
adb -e shell getprop init.svc.bootanim and adb -e shell getprop init.svc.bootanim accordingly
I figured out that sys.boot_completed more reliable than init.svc.bootanim, but anyway I wait both of them. But it does not help, because if after waiting device boot I start connectedAndroidTest task after running about 4 minutes it fails with next exception
Unable to install /Users/busylee/temp/TestRun/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException
at com.android.ddmlib.Device.installRemotePackage(Device.java:1011)
at com.android.ddmlib.Device.installPackage(Device.java:911)
...
Caused by: com.android.ddmlib.ShellCommandUnresponsiveException
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:557)
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:383)
...
But if I wait for a while it completes. Which I guess means that I do not wait something before install test app.
Do you have any ideas what I can rely on while waiting an emulator start?
I have a test.espresso package with all the test classes.
I am trying to run a single test class from the command line, however it ends up running all the test classes.
adb shell am instrument -w \
com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
How do I just run a single test class. I want to use bamboo(which is like jenkins) to run all the test classes individually in separate jobs.
This worked for me (the change is in bold:
adb shell am instrument -w-e class full.path.and.TestClassName\ com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
Based on: https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax (look under options for "class").
If you're using gradle, then there is gradle task you can directly use to achieve it. It would be something like this:
./gradlew connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
To run on specific flavor:
./gradlew connectedMyAppFlavorDebugAndroidTest
It does everything for you, right from building the app, installing on the connected device, run the tests and finally uninstall the app.
If you're not sure about the exact gradle task you need to execute the tests, run the following to get the all available gradle tasks:
./gradlew tasks
You'll get the list of all the tasks with the short description.
To run via command line
Start device. I use Genymotion so I would do
gmtool admin start DeviceName
Install via command line
For ADB
for ADB is should be exactly what the console outputs from Android studio when you start .
$ adb push /Users/x/x-android/app/build/outputs/apk/x-debug.apk
$ adb shell pm install -r "/data/local/tmp/com.x"
$ adb push /x/x/x-android/app/build/outputs/apk/x-debug-androidTest.apk /data/local/tmp/com.x.test
$ adb shell pm install -r "/data/local/tmp/com.x.test"
For Genymotion it is
gmtool device install ~/Desktop/x.apk
gmtool device install ~/Desktop/x-androidTest.apk
For Genymotion connect Genymotion to ADB
gmtool device adbconnect
Start your tests. This is for both ADB and Geny
adb shell am instrument -w -r -e debug false -e class com.x.MyTest com.x.test/android.support.test.runner.AndroidJUnitRunner
I'm adding also how to run it from Gradle here.
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.MyClassTest#myFunctionTest
I'm setting up a Jenkins job in order to run adb monkey on my app. I run the following command:
adb shell monkey -p nl.tmg.telegraaf -v 500
In some cases it succeeds and sometimes it fails. However, the exit code is always 0. Hence jenkins treats it as a successful job. Anybody know how this can be prevented?
You could use the Android Emulator Plugin for Jenkins, which can run Monkey for you, parse the output, and change the build result accordingly.
At some point in my Monkeyrunner I want to launch random Monkey tests (The ones we can get through a command adb shell monkey -p my.package -v 500), So I added this line device.shell('monkey -p my.package -v 500') to my python script. But nothing happens, Any Ideas?
Your command should start the monkey tests. However, you need to pause the script execution during there random monkey tests by adding MonkeyRunner.sleep(no_of_seconds) statements. This will give time for the random tests to complete.
Yes normally it should start it, but it didn't.
Alternatively I imported os import os,
then I called monkey through this command os.system('adb shell monkey -p mypackage -v 500').
Sadly it relaunches the my application. Not the best outcome.
We are developing a ruby script that executes a bunch of shell commands to launch the emulator and run some calabash tests.
PID = fork do
Signal.trap('HUP') { puts 'PROCESS ENDED'; exit }
exec 'emulator -avd TestDevice1'
end
fork do
sleep(55)
exec 'adb shell input keyevent 82'
end
fork do
sleep(60)
exec 'calabash-android run ~/MyApp/MyApp.apk'
Process.Kill('HUP', PID)
end
We are currently using sleep commands so that the calabash tests don't run until the emulator is fully ready. This is not ideal. Is there an Android command to check if the device is ready? By that I mean Android has booted up and the lock screen is displayed.
The most reliable way I have found to detect if the emulator is ready for use, and for Calabash to start the installation process, is to detect when the bootanim has stopped.
You can check whether the emulator has finished booting manually with using ADB in a terminal:
adb shell getprop init.svc.bootanim
I have the following in a Rake command as part of a Calabash test suite which does the trick:
booting = ''
while booting != 'stopped'
booting = `adb shell getprop init.svc.bootanim`.strip
puts 'Waiting for emulator to boot'
sleep 2
end
Hope it works for you!