I have a problem with beanshell.I want to create a BeanShell script that allows me to automate a Robotium test.
I have a shell script that works and lets me do whatever I want, but I'm looking Beanshell equivalent:
#!/bin/bash
echo "on lance l'AVD"
emulator -avd test &
echo "wait the end of launch"
sleep 15
echo "Installation of the application under test"
adb install -r /home/marie/workspace/AndroidCalculator/bin/AndroidCalculator.apk
echo "Installation of the test application"
adb install -r /home/marie/workspace/TestProject/bin/TestProject.apk
echo "Launch of test"
adb shell am instrument -w com.calculator.test/com.neenbedankt.android.test.InstrumentationTestRunner
echo "Saving file results"
adb pull data/data/com.calculator/files/TEST-all.xml ./resultats.xml
echo "killing the AVD"
adb emu kill
How, through BeanShell, I can run the script pre-made, or when an equivalent result by any other means that you can suggest me.
I am looking for answers for 3 days, and I have nothing conclusive
Thank you in advance for your help.
Marie,
u can have look into the integrating ur robotium project with jenkins. Its a build deployment tool. It has plugin which allows to control the android testing.
Have a look at below links:
http://dnlkntt.wordpress.com/2012/08/02/robotium-jenkins-and-ant/
It helped me a lot to automate the test execution process.
Related
I use a Genymotion android emulator for my automated Xamarin UI tests through the bash commands.
The issue is that the emulator is killed by the test runner app after tests are done. So this causes some kind of corruption on the emulator's virtual device file, I suppose.
When I try to start the emulator next time using the same script, I get the following error from Genymotion:
After clicking the update button, Genymotion dashboard opens. Then I can run the emulator by double clicking. But, I cannot do these steps through the shell.
If I could figure out what Genymotion does to repair the emulator, I would do the same thing in the shell script.
Here is my script to run the GM emulator;
cd $HOME
emulatorId=$(VBoxManage list vms | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})" | shuf -n 1)
open -a /Applications/Genymotion.app/Contents/MacOS/player.app --args --vm-name $emulatorId
sleep 5
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
After this command is executed I run my tests like following;
dotnet test Droid.UI.test.dll
Any solution or workaround for skipping this prompt is highly appreciated,
Thanks!
Your script completely overrides the launchpad; that's the problem. Why not use gmtool? It has been designed especially for this type of use.
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
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.
I currently use the Android Monkey tool for stress testing Android system/packages. I find it to be useful. But so far everything has been manual testing (i.e. open emulator, execute adb shell monkey <...>, etc.). I'd like to "automate" this and have it triggered externally by a build server.
My initial instinct is to just write a shell script to execute monkey (using random seeds) and then store the results in an build server accessible file. But is this really useful?
Just curious if anyone has done this before and/or has a "smarter" idea for automating Android Monkey runs. A Google search using terms "automating android monkey" turned up little relevant information.
All thoughts welcome.
Update:
I decided to go with a simple shell script since I couldn't think of anything "smarter" to do. It's still a work in progress. Here it is at it's current state:
#!/bin/bash
REPORTROOT=./reports
# remove old report files
echo "Removing old output report files..."
rm $REPORTROOT
# make dir for new report files
echo "Output reports will be stored in $REPORTROOT..."
mkdir $REPORTROOT
# run monkey on the entire system
echo "Running Monkey on entire system..."
adb -e shell monkey -v -v -v 500 > $REPORTROOT/monkey_sys.txt
# pull the log file from device?
# run monkey on particular packages
# packages here...
# create composite report
echo "Running reports..."
grep -A 5 -h -r CRASH $REPORTROOT > $REPORTROOT/crash_report.txt
The output is a simple .txt file with a few lines about any crashes.
You could look at Hudson - that should be able to start an emulator and then do your android monkey commands.