Unable To Run Espresso Tests With Headless Emulator - android

I created the avd by doing the following:
./avdmanager create avd -c 100M -n test -d 9 -k 'system-images;android-26;google_apis_playstore;x86'
I get the following output after running avdmanager list avd
Name: test
Device: Nexus 5X (Google)
Path: /home/me/.android/avd/test.avd
Target: Google Play (Google Inc.)
Based on: Android 7.1.1 (Nougat) Tag/ABI: google_apis_playstore/x86
Sdcard: 100M
Then I booted up the emulator by running
emulator -avd test -no-audio -no-boot-anim -no-window -skip-adb-auth & adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
Then finally I try to run the tests with
./gradlew connectedDebugAndroidTest
However, the process hangs and I assume will do so indefinitely, but I will kill the process after 10 minutes. I am not even sure how to debug this let one resolve it so any help would be greatly appreciated!

Which process hangs? The test process? In that case you should know which gradle task hangs at least.
However, if it is the emulator process hanging (not finishing booting) then I was able to resolve that in headless environment with these extra params for kvm:
-qemu -enable-kvm -snapshot
Obviously, you need kvm set up and enabled. (KVM installation for ubuntu)

Related

How to repair corrupted/obsolote Genymotion emulator via shell

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.

Adb shell command ocassionally hangs from command line

We have a Xamarin test application, that we run automatically from command line on macOS Sierra. Before it we automatically launch Android emulator from command line. As Android emulator we use x86 emulator, accelerated with Intel HAXM. The script for emulator launching looks in the following way:
function isEmulatorReady {
pathToSDK=$1
#Check that emulator is booted by checking that boot animation is stopped
$pathToSDK/platform-tools/adb wait-for-device shell getprop init.svc.bootanim | grep -m 1 stopped
}
androidSDK=~/Library/Developer/Xamarin/android-sdk-macosx
$androidSDK/platform-tools/adb kill-server
$androidSDK/platform-tools/adb start-server
$androidSDK/tools/emulator -avd Android_Accelerated_x86 -wipe-data -partition-size 512 &
emulatorPID=$!
until isEmulatorReady $androidSDK; do
sleep 1
done
#launch application and wait for end
kill $emulatorPID
Ocassionally adb wait-for-device shell getprop command hangs and script can't detect that emulator is booted, while Android emulator is successfully booted and works. I don't know how to deal with it. The restart of adb server at the beginning doesn't help actually.

Wait for Android emulator to be running before next shell command?

I started an Android emulator using the following shell command:
emulator -avd TEST_AVD
The emulator starts just fine, but the shell script never finishes executing. It just hangs there even after the emulator has completed startup. I have tried with a number of other arguments that I could find, but nothing could quite do what I want it to. How do I know, or stop the shell command, when the emulator is ready to go?
I am setting up our Jenkins CI to use a Jenkinsfile to start the emulator, and then run a series of gradle commands. In short, I'd like to do this:
sh "emulator -avd TEST_AVD"
sh "./gradlew clean test spoon"
However, I don't want to run the gradle tasks until the emulator has finished startup, and I can't figure out how to do that in the terminal.
If you want to do something after you start the emulator you should start it in the background
emulator -avd TEST_AVD &
adb wait-for-device
# other stuff here
adb can wait for a device over a transport to be in a particular state
adb wait-for[-<transport>]-<state>
- wait for device to be in the given state:
device, recovery, sideload, or bootloader
Transport is: usb, local or any [default=any]
To wait until device (or emulator) boots, you can do something like this (as was already answered by Пионерка):
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
Basically:
Wait for device/emulator to be in adb device state
Open shell & sleep in 1 second intervals until the sys.boot_completed property becomes true
If anybody would be interested what Android Studio does, when running emulator, the answer is this class:
If device is online, then it is ready. No need to go to further steps.
Checks system property adb shell getprop dev.bootcomplete until it is equal to 1
For API 23+ devices runs command to unlock screen: adb shell wm dismiss-keyguard
Waits 1 second.

How to connect android using novnc?

First I have installed novnc and sdk in linux, each of them runs correctly, however, I don't know how to connect emulator with novnc. The following commands are used in my experience.
android list targets
android create avd -n myAVD -t 1
emulator -avd myAVD -qemu -vnc 2
vncserver
vncserver -geometry 1024x768 :1
./utils/launch.sh --vnc 127.0.0.1:5901

Check Android Emulator state

I created my android virtual device using command as folow:
android create avd --target 1 --name emu --abi x86
then I tried to run emulator:
emulator -avd emu &
during the emulator starting I was trying to make command as follow:
adb shell
but I had an error:
error: device offline
and when i made command:
echo $?
I had output "1" until emulator get started.
Is it any possibility to check current emulator state using the terminal command?
You can use another terminal window and type adb logcat commnad.

Categories

Resources