Skip to content

Instantly share code, notes, and snippets.

@d4vidi
Created June 13, 2019 11:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save d4vidi/7862d60375b38f8970f824c4ce0ad2a9 to your computer and use it in GitHub Desktop.
Save d4vidi/7862d60375b38f8970f824c4ce0ad2a9 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo ""
echo "[Waiting for launcher to start]"
LAUNCHER_READY=
while [[ -z ${LAUNCHER_READY} ]]; do
UI_FOCUS=`adb shell dumpsys window windows 2>/dev/null | grep -i mCurrentFocus`
echo "(DEBUG) Current focus: ${UI_FOCUS}"
case $UI_FOCUS in
*"Launcher"*)
LAUNCHER_READY=true
;;
"")
echo "Waiting for window service..."
sleep 3
;;
*"Not Responding"*)
echo "Detected an ANR! Dismissing..."
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell input keyevent KEYCODE_ENTER
;;
*)
echo "Waiting for launcher..."
sleep 3
;;
esac
done
echo "Launcher is ready :-)"
@msand
Copy link

msand commented Mar 12, 2020

https://github.com/msand/react-native-svg-e2e/blob/adeff6146daa4d4411253f6e9ecb959c8f069cf0/ci.android-waitforemulator.sh

#!/bin/bash

echo "[Waiting for emulator to finish booting]"
android-wait-for-emulator

echo ""
echo "[Waiting for launcher to start]"
LAUNCHER_READY=
while [[ -z ${LAUNCHER_READY} ]]; do
    UI_FOCUS=`adb shell dumpsys window windows 2>/dev/null | grep -i mCurrentFocus`
    echo "(DEBUG) Current focus: ${UI_FOCUS}"

    case $UI_FOCUS in
    *"Launcher"*)
        LAUNCHER_READY=true
    ;;
    "")
        echo "Waiting for window service..."
        sleep 3
    ;;
    *"ConversationListActivity"*)
        echo "Detected ConversationListActivity, Dismissing..."
        adb shell input keyevent KEYCODE_HOME
    ;;
    *"Not Responding"*)
        echo "Detected an ANR! Dismissing..."
        adb shell input keyevent KEYCODE_DPAD_DOWN
        adb shell input keyevent KEYCODE_DPAD_DOWN
        adb shell input keyevent KEYCODE_ENTER
    ;;
    *)
        echo "Waiting for launcher..."
        sleep 3
    ;;
    esac
done

echo "Launcher is ready :-)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment