標籤:existing 存在 bsp 第二次開啟 ssi erro 解決 client deb
要解決的問題:Appium測試Android混合應用時,第二次切換到WebView時失敗
原因分析:在用Appium測試Android混合應用時,當程式第一次切換到WebView時,可以正常進行自動化測試。可是當程式第二次切換到WebView時,Appium會自動找到到第一次開啟的Html頁面,那麼這時Appium就無法定位我們第二次開啟的Html頁面中的元素。
Appium第一次切換到Html頁面時,會新產生一個Chromedriver;當第二次切換到Html時,會使用已經存在的Chromedriver。但其實在我們的應用裡面每次開啟一個Activity時一般都是會重新建立一個WebChromeClient,所以這裡就把它改成無論如何都產生一個新的Chromedriver。
解決步驟:修改Appium源碼
Appium安裝目錄下的檔案
Appium\node_modules\appium\lib\devices\android\android-hybrid.js,檔案中有這樣一個函數:
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); } };
改為:
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); // } this.setupNewChromedriver(context, cb); };
【親測】Appium測試Android混合應用時,第二次切換到WebView失敗