【親測】Appium測試Android混合應用時,第二次切換到WebView失敗

來源:互聯網
上載者:User

標籤: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失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.