Appium Android Driver 简单修改

【注】文中提起的 Appium 版本為 v1.6.5

对 Appium Driver 进行简单的修改,并更新方式如下:

  1. 修改 appium-android-driver 中文件,比如去掉对 app 依赖的错误日志
$ vim appium-android-driver/lib/driver.js

具体修改如下:

  diff --git a/lib/driver.js b/lib/driver.js
  index 2e60375..fbe2035 100644
  --- a/lib/driver.js
  +++ b/lib/driver.js
  @@ -444,7 +444,8 @@ class AndroidDriver extends BaseDriver {
  if ((!caps.browserName || !helpers.isChromeBrowser(caps.browserName)) &&
!caps.app && !caps.appPackage) {
let msg = 'The desired capabilities must include either an app, appPackage or browserName';
 -      log.errorAndThrow(msg);
 +      //log.errorAndThrow(msg);
 +      log.warn(msg);
 }
 // warn if the capabilities have both `app` and `browser, although this
 // is common with selenium grid
  1. 编译并安装修改:
 $ npm install
  1. 执行测试即可:
void setupAndroid(String url, String deviceName, String udid, String version, File app, String browserName,
            String packageName, String activity) throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, version);
        if (StringUtils.isEmpty(deviceName)) {
            deviceName = "Android";
        }
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
        // support Chinese
        capabilities.setCapability("unicodeKeyboard", "True");
        capabilities.setCapability("resetKeyboard", "True");
        // support noSign apk
        capabilities.setCapability("noSign", "True");
        if (!StringUtils.isEmpty(udid)) {
            capabilities.setCapability(MobileCapabilityType.UDID, udid);
        }
        if (!StringUtils.isEmpty(packageName) && !StringUtils.isEmpty(activity)) {
            capabilities.setCapability("appPackage", packageName);
            capabilities.setCapability("appActivity", activity);
        } else if (app != null) {
            capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
        } else if (!StringUtils.isEmpty(browserName)) {
            capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, browserName);
        } else {
            capabilities.setCapability("autoLaunch", false);
        }
        mDriver = new AndroidDriver<MobileElement>(new URL(url), capabilities);
}
setupAndroid("http://127.0.0.1:4492/wd/hub", null, null, null, null, nul, null);
上一篇:【死磕JDK源码】ThreadPoolExecutor源码保姆级详解(中)


下一篇:让自己专注起来