Skip to content

Commit

Permalink
support webview verison
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Jul 25, 2017
1 parent cd8e2b3 commit c404bc4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
54 changes: 47 additions & 7 deletions lib/macaca-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Android.prototype.initDevice = function *() {
this.adb.setDeviceId(device.udid);
this.udid = device.udid;
} else {
console.log('no device, now create one from avd');
logger.info('no device, now create one from avd');
var env = global.process.env;
var emulatorCommand = path.resolve(env.ANDROID_HOME, 'tools', 'emulator');
var androidCommand = path.resolve(env.ANDROID_HOME, 'tools', 'android');
Expand Down Expand Up @@ -233,7 +233,7 @@ Android.prototype.unlock = function *() {

const isInstalled = yield this.adb.isInstalled(UnlockApk.package);
if (isInstalled) {
this.checkApkVersion(UnlockApk.apkPath,UnlockApk.package);
this.checkApkVersion(UnlockApk.apkPath, UnlockApk.package);
} else {
yield this.adb.install(UnlockApk.apkPath);
}
Expand All @@ -247,7 +247,7 @@ Android.prototype.unlock = function *() {
}
};

Android.prototype.checkApkVersion = function *(app , pkg) {
Android.prototype.checkApkVersion = function *(app, pkg) {
var newVersion = yield ADB.getApkVersion(app);
var oldVersion = yield this.adb.getInstalledApkVersion(pkg);
if (newVersion > oldVersion) {
Expand Down Expand Up @@ -297,7 +297,26 @@ Android.prototype.launchApk = function *() {

Android.prototype.getWebviews = function *() {
if (!this.chromedriver) {
yield this.initChromeDriver();
var webviewVersion = null;
try {
webviewVersion = yield this.adb.getWebviewVersion();
} catch (error) {
logger.info('No webview version found from adb shell!');
webviewVersion = null;
}
try {
if (webviewVersion) {
yield this.initChromeDriver({
webviewVersion: webviewVersion
});
} else {
yield this.initChromeDriver({});
}
} catch (error) {
logger.error('initChromeDriver failed!' + error);
this.chromedriver = null;
return [];
}
}
this.proxy = this.chromedriver;

Expand All @@ -309,13 +328,34 @@ Android.prototype.getWebviews = function *() {
return webviews;
};

Android.prototype.initChromeDriver = function() {
return new Promise(resolve => {
this.chromedriver = new ChromeDriver();
Android.prototype.initChromeDriver = function(options) {
return new Promise((resolve, reject) => {
this.chromedriver = new ChromeDriver(options);
if (this.chromedriver.binPathReady) {
logger.info(`starting chromedriver service!`);
this.chromedriver.start({
chromeOptions: {
androidPackage: this.apkInfo.package,
androidUseRunningApp: true,
androidDeviceSerial: this.udid,
androidProcess: this.apkInfo.androidProcess
}
});
}
this.chromedriver.on(ChromeDriver.BIN_READY, data => {
logger.info(`chromedriver bin file ready: ${data}`);
});
this.chromedriver.on(ChromeDriver.EVENT_READY, data => {
logger.info(`chromedriver ready with: ${JSON.stringify(data)}`);
resolve('');
});
this.chromedriver.on(ChromeDriver.EVENT_ERROR, data => {
logger.error(`chromedriver error with: ${data}`);
reject(data);
});

logger.info(`starting chromedriver service!`);

this.chromedriver.start({
chromeOptions: {
androidPackage: this.apkInfo.package,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-android",
"version": "2.0.29",
"version": "2.0.30",
"description": "Macaca Android driver",
"keywords": [
"android",
Expand Down

0 comments on commit c404bc4

Please sign in to comment.