I'm currently trying to automate few steps in android ICS CTS.
When we execute ./cts-tradefed we get cts-tf > prompt.
then I am able to enter run cts --plan CTS
then exit command to exit from prompt.
Here I want to write all the above 3 steps in one shell script. But unable to do it with below script. Tried in many way but could not achieve it. Please help.
Want to execute:
1. ./cts-tradefed
2. run cts --plan CTS exit
3. ./cts-tradefed
4. run cts --plan CTS
5. exit
Help in any shell, python or perl languages appreciated.
Excerpt from help of CTS-tradefed (version 6.0_r0)
exit: gracefully exit the cts console, waiting till all invocations are complete
We can leverage above argument to serve the purpose as follows:
echo exit | cts-tradefed <arguments to cts>
I am not sure which version of CTS you are using, so I assume the version is 4.0.3_r3.
You could execute the command ./cts-tradefed run cts --plan CTS in one line.
However, the prompt still exist after finish the command.
According to this issue,
I think there are no simple ways to solve it.
Therefore, I just apply the patch in the above link, and execute the following command:
echo | ./cts-tradefed run cts --plan CTS
With Android CTS 7.0, you can simply run this command line, it's most convenient for automation:
(Assume "cts-tradefed" is in your PATH.)
$ cts-tradefed run commandAndExit cts
Help from cts-tradefed:
r(?:un)? help:
commandAndExit <config> [options] Run the specified command, and run 'exit -c' immediately afterward
cmdfileAndExit <cmdfile.txt> Run the specified commandfile, and run 'exit -c' immediately afterward
Related
I'm too lazy to reach out and tap the application icon on my tablet. After installing and testing, how do I tell ./gradlew to launch the app? This command returns nothing:
$ ./gradlew tasks --all | grep -i launch
A related question that might fix my ulterior problem is: How to write an Android app that prefers to be on all the time? My app is in-house, so our tablets have no reason to exist except to run our app.
Per CommonsWare's comment, try:
adb -s WHATEVER shell am start -n com.mycorp.myapp/com.mycorp.myapp.MainActivity
and forget gradlew because I have all my command lines in a Rakefile already because it's easy to maintain.
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.
Given that I in my workspace I have an android project MyAndroidProject and my tests project MyAndroidProjectTests directories how could I write a pre-commit git hook that will run the tests in the MyAndroidProjectTests and refuse to commit any code changes if the tests fail?
When I run tests on the terminal they usually have output like this:
com.mydomain.tests.Models.MyProjectTests:.......
Test results for InstrumentationTestRunner=.......
Time: 0.05
OK (10 tests)
What I'm unsure about is how to what to use to try to determine if the tests passed or failed other than parsing the output of the last line (e.g. OK or FAILED and I'm not sure I like that method so much. I ideally I'd like a status to be returned from the command I use to run tests on the terminal:
adb shell am instrument -w com.mydomain.tests/android.test.InstrumentationTestRunner
I'd like to use the response in a shell script that I could place in the .git/hooks/ folder as a pre-commit hook.
I would appreciate any info or links to other resources and much thanks in advance.
git hooks are executed from your project/repo root - so you should be able to just use your command directly in a precommit hook:
#!/bin/bash
adb shell am instrument -w com.mydomain.tests/android.test.InstrumentationTestRunner
if adb returns a none-zero exist code on failure - the commit will be aborted.
If you need to get the exit code for another purpose there are other questions indicating exactly how to do that.
How can I run my android junit/robotium tests from the command line on every single emulator? I want to make sure my tests run on many android OS versions and many screen resolutions.
I'd like to write a batch file that runs from the windows command line to run my test suite over and over again on each emulator I have installed.
To run from the command line I can do this:
adb shell am instrument -w
com.myapp.client.test/android.test.InstrumentationTestRunner
but that just runs it on the default emulator. How can I force that command to run on all of the emulators I have setup?
Ideally, the batch file would looking something like:
launch emulator1
run tests
close emulator1
launch emulator2
run tests
close emulator2
...
I don't know how to do the launch and close part.
Thanks
EDIT: Found solutions. Below is my batch file
set PORTRAIT=medium
set LANDSCAPE=large
:: launch emulator
emulator -avd android2.2
:: wait for emulator to load
adb wait-for-device
:: install apps?
:: run tests in portrait
adb shell am instrument -w -e size %PORTRAIT% com.myapp.client.test/android.test.InstrumentationTestRunner
:: run tests in landscape
adb shell am instrument -w -e size %LANDSCAPE% com.myapp.client.test/android.test.InstrumentationTestRunner
:: pull screenshots
adb pull /sdcard/ c:\
:: close/kill emulator (android bug here, so must use windows taskkill)
taskkill /IM emulator-arm.exe
I would really recommend you looking to use something like Jenkins to handle this for you. You can use the android emulator plugin to build up a whole matrix of API versions/Screen size to have your tests run against.