forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.bat
236 lines (212 loc) · 7.88 KB
/
reset.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
@echo off
:: Go to directory containing batch file
FOR /f %%i in ("%0") DO SET curpath=%%~dpi
CD /d %curpath%
:: Flags to determine which parts will be executed
SET doDev=0
SET doSelendroid=0
SET doAndroid=0
SET doVerbose=0
SET doForce=0
SET pigsFly=0
SET chromedriver_version=
SET udid=
:: Read in command line switches
:loop
IF "%~1" neq "" (
IF "%1" == "--dev" SET doDev=1
IF "%1" == "--android" SET doAndroid=1
IF "%1" == "--selendroid" SET doSelendroid=1
IF "%1" == "--verbose" SET doVerbose=1
IF "%1" == "--force" SET doForce=1
IF "%1" == "--chromedriver-version" IF "%2" neq "" (
SET "chromedriver_version=%2"
)
IF "%1" == "--udid" IF "%2" neq "" (
SET "udid=%2"
)
shift
goto :loop
)
:: If nothing is flagged do only android
IF %doDev% == 0 IF %doSelendroid% == 0 IF %doAndroid% == 0 SET doAndroid=1
:: Install Package and Dependencies
ECHO.
ECHO =====Installing dependencies with npm=====
ECHO.
CALL :runCmd "npm install ."
ECHO =====Finished installing dependencies with npm=====
ECHO.
:: Install Dev Dependencies
if %doDev% == 1 (
ECHO.
ECHO =====Installing development dependencies with npm=====
ECHO.
CALL :runCmd "npm install . --dev"
ECHO =====Finished installing development dependencies with npm=====
ECHO.
)
:: Reset Android
if %doAndroid% == 1 (
ECHO.
ECHO =====Resetting Android=====
ECHO.
CALL :runCmd "node_modules\.bin\grunt configAndroidBootstrap"
CALL :runCmd "node_modules\.bin\grunt buildAndroidBootstrap"
CALL :runCmd "node_modules\.bin\grunt setConfigVer:android"
ECHO.
ECHO =====Reset Android Complete=====
ECHO.
ECHO =====Resetting Unlock.apk=====
ECHO.
CALL :runCmd "RD /S /Q build\unlock_apk | VER > NUL"
CALL :runCmd "MKDIR build\unlock_apk"
ECHO Building Unlock.apk
CALL :runCmd "git submodule update --init submodules\unlock_apk"
CALL :runCmd "PUSHD submodules\unlock_apk"
CALL :runCmd "ant clean"
CALL :runCmd "ant debug"
CALL :runCmd "POPD"
CALL :runCmd "COPY submodules\unlock_apk\bin\unlock_apk-debug.apk build\unlock_apk\unlock_apk-debug.apk"
ECHO.
ECHO =====Reset Unlock.apk Complete=====
:: Reset Android Dev
IF %doDev% == 1 (
ECHO.
ECHO =====Resetting API Demos=====
ECHO.
ECHO Cloning/updating Android test app: ApiDemos
CALL :runCmd "git submodule update --init submodules\ApiDemos"
CALL :runCmd "RD /S /Q sample-code\apps\ApiDemos | VER > NUL"
CALL :runCmd "MKDIR sample-code\apps\ApiDemos"
CALL :runCmd "XCOPY submodules\ApiDemos sample-code\apps\ApiDemos /E /Q"
CALL :runCmd "node_modules\.bin\grunt configAndroidApp:ApiDemos"
CALL :runCmd "node_modules\.bin\grunt buildAndroidApp:ApiDemos"
ECHO.
ECHO =====Reset API Demos Complete=====
)
:: Reset ChromeDriver
echo =====Resetting ChromeDriver=====
setlocal enabledelayedexpansion
SET "chromedriver_build_directory=.\build\chromedriver\windows"
echo Building directory structure
IF NOT EXIST .\build CALL :runCmd "mkdir .\build"
IF NOT EXIST .\build\chromedriver CALL :runCmd "mkdir .\build\chromedriver"
IF NOT EXIST .\build\chromedriver\windows CALL :runCmd "mkdir !chromedriver_build_directory!"
echo Removing old files
IF EXIST !chromedriver_build_directory!\chromedriver.zip CALL :runCmd "del !chromedriver_build_directory!\chromedriver.zip"
IF EXIST !chromedriver_build_directory!\chromedriver.exe CALL :runCmd "del !chromedriver_build_directory!\chromedriver.exe"
IF NOT DEFINED chromedriver_version (
echo Finding latest version
for /f "delims=" %%a in ('curl -L http://chromedriver.storage.googleapis.com/LATEST_RELEASE') do SET "chromedriver_version=%%a"
)
echo !chromedriver_build_directory!
echo Downloading and installing version !chromedriver_version!
CALL :runCmd "curl -L http://chromedriver.storage.googleapis.com/!chromedriver_version!/chromedriver_win32.zip -o !chromedriver_build_directory!\chromedriver.zip"
CALL :runCmd "PUSHD !chromedriver_build_directory!"
CALL :runCmd "jar xf chromedriver.zip"
CALL :runCmd "del chromedriver.zip"
CALL :runCmd "POPD"
echo =====Reset ChromeDriver Complete=====
)
:: Reset Selendroid
IF %doSelendroid% == 1 (
ECHO.
ECHO =====Resetting Selendroid=====
ECHO.
ECHO Clearing out any old modified server apks
CALL :runCmd "RD -/S /Q %windir%\Temp\selendroid*.apk | VER > NUL"
ECHO Cloning/updating selendroid
CALL :runCmd "RD -/S /Q submodules\selendroid\selendroid-server\target | VER > NUL"
CALL :runCmd "git submodule update --init submodules\selendroid"
CALL :runCmd "RD /S /Q selendroid | VER > NUL"
ECHO Building selendroid server and supporting libraries
CALL :runCmd "set MAVEN_OPTS=-Xss1024k"
CALL :runCmd "node_modules\.bin\grunt buildSelendroidServer"
CALL :runCmd "set MAVEN_OPTS="
:: Reset Selendroid Dev
IF %doDev% == 1 (
ECHO.
ECHO =====Resetting Selendroid - Dev=====
ECHO.
ECHO Linking selendroid test app: WebViewDemo
CALL :runCmd "RD /S /Q sample-code\apps\WebViewDemo | VER > NUL"
CALL :runCmd "MKDIR sample-code\apps\WebViewDemo"
CALL :runCmd "XCOPY submodules\selendroid\selendroid-test-app sample-code\apps\WebViewDemo /E /Q"
CALL :uninstallAndroidApp com.example.android.apis.selendroid
CALL :uninstallAndroidApp io.selendroid.testapp
CALL :uninstallAndroidApp io.selendroid.testapp.selendroid
CALL :uninstallAndroidApp org.openqa.selendroid.testapp
CALL :uninstallAndroidApp openqa.selendroid.testapp.selendroid
ECHO.
ECHO =====Reset Selendroid - Dev Complete=====
)
ECHO Setting Selendroid config to Appium's version
CALL :runCmd "node_modules\.bin\grunt setConfigVer:selendroid"
ECHO.
ECHO =====Reset Selendroid Complete=====
)
:: Reset Gappium
IF %pigsFly% == 1 (
ECHO.
ECHO =====Resetting Gappium=====
ECHO.
ECHO Clearing out old links
CALL :runCmd "RD /S /Q sample-code\apps\io.appium.gappium.sampleapp | VER > NUL"
ECHO Cloning/updating Gappium
CALL :runCmd "git submodule update --init submodules\io.appium.gappium.sampleapp"
CALL :runCmd "PUSHD submodules\io.appium.gappium.sampleapp"
ECHO Building Gappium test app
CALL :runCmd "reset.bat"
CALL :runCmd "POPD"
ECHO Linking Gappium test app
CALL :runCmd "XCOPY submodules\io.appium.gappium.sampleapp sample-code\apps\io.appium.gappium.sampleapp /E /Q"
ECHO.
ECHO =====Reset Gappium=====
)
ECHO Done, No Errors
GOTO :EOF
:: Function to uninstall an Android app
:uninstallAndroidApp
ECHO Attempting to uninstall android app %~1
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
:runCmd - function to run a command
IF %doVerbose% == 1 ECHO %~1
CALL %~1
IF %ERRORLEVEL% NEQ 0 IF %doForce% == 0 (
CD /D %curpath%
ECHO.
ECHO Stopping because there was an error and --force was not used
CALL :halt 1
)
GOTO :EOF
:: Sets the errorlevel and stops the batch immediately
:halt
CALL :__SetErrorLevel %1
CALL :__ErrorExit 2> NUL
GOTO :EOF
:__ErrorExit
REM Creates a syntax error, stops immediately
()
GOTO :EOF
:__SetErrorLevel
EXIT /B %TIME:~-2%
GOTO :EOF