Skip to content

Commit

Permalink
Merge pull request #1908 from imurchie/isaac-reset-batch
Browse files Browse the repository at this point in the history
Bundle chromedriver into build, for Windows
  • Loading branch information
jlipps committed Feb 13, 2014
2 parents 63b9c9d + e9d59b8 commit 706a610
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
3 changes: 1 addition & 2 deletions docs/mobile-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ remoteWebDriver.quit();
Pre-requisites:

* Make sure Chrome (an app with the package `com.android.chrome`) is installed on your device or emulator. Getting Chrome for the x86 version of the emulator is not currently possible without building Chromium, so you may want to run an ARM emulator and then copy a Chrome APK from a real device to get Chrome on an emulator.
* For Windows, make sure [ChromeDriver](http://chromedriver.storage.googleapis.com/index.html), version >= 2.0 is on your system and that the `chromedriver` binary is on your `$PATH`.
* For Mac, if downloaded from [NPM](https://www.npmjs.org/package/appium), or running from the [.app](https://github.com/appium/appium-dot-app), nothing needs to be done. If running from source, `reset.sh` will download ChromeDriver and put it in `build`. A particular version can be specified by passing the `--chromedriver-version` option (e.g., `./reset.sh --android --chromedriver-version 2.8`), otherwise the most recent one will be retrieved.
* If downloaded from [NPM](https://www.npmjs.org/package/appium), or running from the [.app](https://github.com/appium/appium-dot-app), nothing needs to be done. If running from source, the `reset` script will download ChromeDriver and put it in `build`. A particular version can be specified by passing the `--chromedriver-version` option (e.g., `./reset.sh --android --chromedriver-version 2.8`), otherwise the most recent one will be retrieved.

Then, use desired capabilities like these to run your test in Chrome:

Expand Down
15 changes: 5 additions & 10 deletions lib/devices/android/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var Android = require('./android.js')
, through = require('through')
, isWindows = require('../../helpers.js').isWindows()
, ADB = require('./adb.js')
, path = require('path');
, path = require('path')
, fs = require('fs');

var ChromeAndroid = function (opts) {
this.initialize(opts);
Expand Down Expand Up @@ -52,16 +53,10 @@ ChromeAndroid.prototype.unlock = function (cb) {

ChromeAndroid.prototype.ensureChromedriverExists = function (cb) {
logger.info("Ensuring Chromedriver exists");
if (isWindows) {
exec("where chromedriver.exe", function (err, stdout) {
if (err) return cb(new Error("Could not find chromedriver, is it on PATH?"));
this.chromedriver = stdout.trim();
cb();
}.bind(this));
} else {
// use Appium's Chromedriver
fs.exists(this.chromedriver, function (exists) {
if (!exists) return cb(new Error("Could not find chromedriver. Need to run reset script?"));
cb();
}
});
};

ChromeAndroid.prototype.killOldChromedrivers = function (cb) {
Expand Down
48 changes: 38 additions & 10 deletions reset.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
SETLOCAL

:: Go to directory containing batch file
FOR /f %%i in ("%0") DO SET curpath=%%~dpi
Expand All @@ -13,11 +14,20 @@ SET doForce=0
SET pigsFly=0

:: Read in command line switches
FOR %%A IN (%*) DO IF "%%A" == "--dev" SET doDev=1
FOR %%A IN (%*) DO IF "%%A" == "--android" SET doAndroid=1
FOR %%A IN (%*) DO IF "%%A" == "--selendroid" SET doSelendroid=1
FOR %%A IN (%*) DO IF "%%A" == "--verbose" SET doVerbose=1
FOR %%A IN (%*) DO IF "%%A" == "--force" SET doForce=1
: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"
shift
)
shift
goto :loop
)

:: If nothing is flagged do only android
IF %doDev% == 0 IF %doSelendroid% == 0 IF %doAndroid% == 0 SET doAndroid=1
Expand Down Expand Up @@ -47,7 +57,7 @@ if %doAndroid% == 1 (
CALL :runCmd "node_modules\.bin\grunt setConfigVer:android"
ECHO.
ECHO =====Reset Android Complete=====

ECHO.
ECHO =====Resetting Unlock.apk=====
ECHO.
Expand Down Expand Up @@ -78,6 +88,24 @@ if %doAndroid% == 1 (
ECHO.
ECHO =====Reset API Demos Complete=====
)

:: Reset ChromeDriver
echo =====Resetting ChromeDriver=====
echo Removing old files
IF EXIST .\build\chromedriver.zip CALL :runCmd "del .\build\chromedriver.zip"
IF EXIST .\build\chromedriver.exe CALL :runCmd "del .\build\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 Downloading and installing version %chromedriver_version%
CALL :runCmd "curl -L http://chromedriver.storage.googleapis.com/%chromedriver_version%/chromedriver_win32.zip -o .\build\chromedriver.zip"
CALL :runCmd "PUSHD .\build"
CALL :runCmd "unzip chromedriver.zip"
CALL :runCmd "del chromedriver.zip"
CALL :runCmd "POPD"
)

:: Reset Selendroid
Expand All @@ -95,7 +123,7 @@ IF %doSelendroid% == 1 (
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.
Expand All @@ -112,7 +140,7 @@ IF %doSelendroid% == 1 (
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"
Expand Down Expand Up @@ -165,9 +193,9 @@ GOTO :EOF

:__ErrorExit
REM Creates a syntax error, stops immediately
()
()
GOTO :EOF

:__SetErrorLevel
EXIT /B %TIME:~-2%
GOTO :EOF
GOTO :EOF

0 comments on commit 706a610

Please sign in to comment.