appium 切换到webview context后报错

来源:互联网 发布:matlab矩阵最大值位置 编辑:程序博客网 时间:2024/06/07 17:21

错误1: chrome not reachable
解决办法:原文链接
修改Appium安装目录下的文件,例如:

D:\Program Files\Appium\node_modules\appium\lib\devices\android\android-hybrid.js

找到androidHybrid.startChromedriverProxy 函数,注释掉相关内容。

androidHybrid.startChromedriverProxy = function (context, cb) {  cb = _.once(cb);  logger.debug("Connecting to chrome-backed webview");  if (this.chromedriver !== null) {    return cb(new Error("We already have a chromedriver instance running"));  }  //if (this.sessionChromedrivers[context]) {    // in the case where we've already set up a chromedriver for a context,    // we want to reconnect to it, not create a whole new one  //  this.setupExistingChromedriver(context, cb);  //} else {    this.setupNewChromedriver(context, cb);  //}};

问题原因:

Appium第一次切换到Html页面时,会新生成一个Chromedriver;当第二次切换到Html时,会使用已经存在的Chromedriver。但其实在我们的应用里面每次打开一个Activity时一般都是会重新创建一个WebChromeClient,所以这里就把它改成无论如何都生成一个新的Chromedriver。
另外一个问题:修改源码后不起作用,需要重新编译。目前没找打编译方法。一个workround:切换为webview后,重新切换回native_app前杀死chromdriver进程。

错误2:no such session
解决方法:
查看手机端系统内核chrom版本: 设置—应用管理–全部—Android System Webview。点击进入查看版本。chrome与chromedriver对应关系

chromedriver下载地址:http://chromedriver.storage.googleapis.com/index.html
下载对应的chromedriver后替换appium自带的chromdirver。路径:appium安装路径\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
注:
双击执行“chromedriver.exe”,可以查看版本driver版本号;

阅读全文
0 0