2016-02-22 23:37:41 +08:00
|
|
|
/* jshint node: true */
|
2016-02-04 23:55:57 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var wd = global.WD || require('wd');
|
|
|
|
var driver;
|
|
|
|
|
|
|
|
module.exports.getDriver = function (platform, callback) {
|
|
|
|
var serverConfig = {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 4723
|
|
|
|
},
|
|
|
|
driverConfig = {
|
|
|
|
browserName: '',
|
2016-03-01 23:27:08 +08:00
|
|
|
'appium-version': '1.5',
|
2016-02-04 23:55:57 +08:00
|
|
|
platformName: platform,
|
|
|
|
platformVersion: global.PLATFORM_VERSION || '',
|
|
|
|
deviceName: global.DEVICE_NAME || '',
|
|
|
|
app: global.PACKAGE_PATH,
|
2016-02-16 21:28:43 +08:00
|
|
|
autoAcceptAlerts: true,
|
2016-02-04 23:55:57 +08:00
|
|
|
};
|
|
|
|
|
2016-02-16 21:28:43 +08:00
|
|
|
if (process.env.CHROMEDRIVER_EXECUTABLE) {
|
|
|
|
driverConfig.chromedriverExecutable = process.env.CHROMEDRIVER_EXECUTABLE;
|
|
|
|
}
|
2016-02-04 23:55:57 +08:00
|
|
|
driver = wd.promiseChainRemote(serverConfig);
|
|
|
|
module.exports.configureLogging(driver);
|
2016-02-22 23:37:41 +08:00
|
|
|
|
|
|
|
return driver.init(driverConfig).setImplicitWaitTimeout(10000)
|
2016-02-04 23:55:57 +08:00
|
|
|
.sleep(20000) // wait for the app to load
|
|
|
|
.then(callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.getWD = function () {
|
|
|
|
return wd;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.configureLogging = function (driver) {
|
|
|
|
driver.on('status', function (info) {
|
|
|
|
console.log(info);
|
|
|
|
});
|
|
|
|
driver.on('command', function (meth, path, data) {
|
|
|
|
console.log(' > ' + meth, path, data || '');
|
|
|
|
});
|
|
|
|
driver.on('http', function (meth, path, data) {
|
|
|
|
console.log(' > ' + meth, path, data || '');
|
|
|
|
});
|
|
|
|
};
|