From 29f393452df81bd2e607b8cb3ebf6bc73c74cb18 Mon Sep 17 00:00:00 2001 From: Payman Delshad Date: Wed, 5 Mar 2014 10:20:55 +0100 Subject: [PATCH] Added support for --udid to the reset scripts. --- reset.bat | 31 ++++++++++++++++++++++++------- reset.sh | 13 ++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/reset.bat b/reset.bat index 9aed348e2..7752859a6 100644 --- a/reset.bat +++ b/reset.bat @@ -11,6 +11,8 @@ SET doAndroid=0 SET doVerbose=0 SET doForce=0 SET pigsFly=0 +SET chromedriver_version= +SET udid= :: Read in command line switches :loop @@ -22,7 +24,9 @@ IF "%~1" neq "" ( IF "%1" == "--force" SET doForce=1 IF "%1" == "--chromedriver-version" IF "%2" neq "" ( SET "chromedriver_version=%2" - shift + ) + IF "%1" == "--udid" IF "%2" neq "" ( + SET "udid=%2" ) shift goto :loop @@ -183,12 +187,25 @@ GOTO :EOF :: Function to uninstall an Android app :uninstallAndroidApp ECHO Attempting to uninstall android app %~1 - FOR /F "delims=" %%i in ('adb devices ^| find /v /c ""') DO SET deviceCount=%%i - IF %deviceCount% GTR 2 ( - CALL :runCmd "adb uninstall %~1 | VER > NUL" - ) ELSE ( - ECHO No android devices detected, skipping uninstallation - ) + FOR /F "delims=" %%i in ('adb devices ^| FINDSTR /R "device$" ^| find /v /c ""') DO SET deviceCount=%%i + IF %deviceCount% GEQ 1 ( + GOTO :deviceExists + ) ELSE ECHO No android devices detected, skipping uninstallation +GOTO :EOF + +:deviceExists +IF DEFINED udid ( + GOTO :udidSpecified +) ELSE IF %deviceCount% EQU 1 ( + CALL :runCmd "adb uninstall %~1 | VER > NUL" +) ELSE ECHO More than one device present, but no device serial provided, skipping uninstallation (use --udid) +GOTO :EOF + +:udidSpecified +FOR /F "delims=" %%i in ('adb devices ^| FINDSTR /R "^%udid%" ^| find /v /c ""') DO SET specifiedDeviceCount=%%i +IF %specifiedDeviceCount% EQU 1 ( + CALL :runCmd "adb -s %udid% uninstall %~1 | VER > NUL" +) ELSE ECHO Device with serial %udid% not found, skipping installation GOTO :EOF :: Function to run commands diff --git a/reset.sh b/reset.sh index 67006e86f..09a1e0f74 100755 --- a/reset.sh +++ b/reset.sh @@ -44,6 +44,7 @@ do "--hardcore") hardcore=true;; "--chromedriver-version") chromedriver_version=$2;; "--chromedriver-install-all") chromedriver_install_all=true;; + "--udid") udid=$2;; esac if [[ -n "$2" ]] && [[ "$2" != --* ]]; then @@ -235,7 +236,17 @@ uninstall_android_app() { echo "* Attempting to uninstall android app $1" if (which adb >/dev/null); then if (adb devices | grep "device$" >/dev/null); then - run_cmd adb uninstall $1 + if [[ ! -z $udid ]]; then + if (adb devices | grep "^$udid" >/dev/null); then + run_cmd adb -s $udid uninstall $1 + else + echo "* Device with serial $udid not found, skipping" + fi + elif [[ $(adb devices | grep "device$" | wc -l) -eq 1 ]]; then + run_cmd adb uninstall $1 + else + echo "* More than one device present, but no device serial provided, skipping (use --udid)" + fi else echo "* No devices found, skipping" fi