Chromedriver 能对 webview 进行自动化测试或者 chrome 浏览器的检查设备能调试 webview 的原因在于,当打开 webview 的时候,
会有一个调试的 socket 生成,一般是 webview_devtools_remote_pid 或者 chrome_devtools_remote。但是 crosswalk 是自定义的 xxxx_devtools_remote。

悲剧的是 ChromeDriver 写死了 chrome_devtools_remote。所以导致无法使用 ChromeDriver 来自动化 crosswalk 的 webview, Appium 自然也无力了。
不过听说 crosswalk 也在出 driver,说不定过段时间就可以用上了。

package.json


{
  "name": "crosswalk_app_test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "dependencies": {
     "chrome-remote-interface": "0.7.0",
     "appium-adb": "1.7.5",
     "npmlog": "~1.1.0",
     "date-utils": "~1.2.16",
     "winston": "~0.9.0"
  },
  "license": "ISC"
}

test.js

var Chrome = require('chrome-remote-interface'),
  logFactory = require('./logger.js'),
  logger = null,
  adb = null;


logFactory.init({"loglevel": "debug"});
logger = logFactory.get("Test");

var ADB = require('./adb.js');

var sleep = function (milliSeconds) {
  var startTime = new Date().getTime();
  while (new Date().getTime() < startTime + milliSeconds);
};

ADB.createADB({}, function (e, _adb) {
  if (e) return;
  adb = _adb;
});

adb.startApp(
  {
    pkg: "com.jiudao.ccare",
    activity: ".MainActivity",
    waitPkg: "com.jiudao.ccare",
    waitActivity: ".MainActivity"
  }, function () {
    sleep(10000);
    adb.forwardAbstractPort(9222, "com.jiudao.ccare_devtools_remote", function () {
    });
    Chrome(function (chrome) {
      with (chrome) {
        Network.enable();
        Page.enable();
        once('ready', function () {
          chrome.send('Runtime.evaluate', {expression: "document.getElementById('username').value='hello'"}, logger.debug);
          chrome.send('Runtime.evaluate', {expression: "document.getElementsByTagName('input')[1].value=1"}, logger.debug);

        });
      }
    }).on('error', function () {
      console.error('Cannot connect to Chrome');
    });
  });


↙↙↙阅读原文可查看相关链接,并与作者交流