Appium - WebView測試(Android)

來源:互聯網
上載者:User

標籤:inf   作者   his   click   contains   ntb   system   cli   getc   

Appium - WebView測試

作者: Max.Bai

時間: 2015/07



Appium - WebView測試(Android)

如今App都是混合型的。有原生的也包括WebView的,appium測試的時候就須要在原生和WebView之間切換才幹完畢測試。


1. 查看全部context

查看當前全部的表單

Set<String> contextNames = driver.getContextHandles();System.print(contextNames);
結果包括眼下全部開啟的app, 比如我開啟了ES,我的被測應用,還有另外一個應用,

[NATIVE_APP, WEBVIEW_com.test.android, WEBVIEW_com.estrongs.android.pop, WEBVIEW_com.xxxxx.sjj]

NATIVE_APP就是我的被測應用原生介面

WEBVIEW_com.test.android 是我的被測應用開啟的WebView

另外兩個一個是ES, 一個其它的應用(混合型的)


2.切換到WebView

通過上面方法獲得當前的全部context

我們能夠通過context方法切換到指定的應用

<pre name="code" class="java">driver.context("WEBVIEW_com.test.android");driver.findElementByID("wd");

切換完畢後就能夠像測試web應用一樣測試了,全部的定位和web同樣。
 

3. 切換到NativeApp

測試完web應用,須要操作原生應用的時候就須要切換回NATIVE_APP

我們能夠通過context方法切換到原生應用

<pre name="code" class="java">driver.context("NATIVE_APP");
這樣之後的操作就都是原生應用的操作了
 

4. Demo

/** * Switch to NATIVE_APP or WEBVIEW * @param sWindow window name */private void switchToWindow(String sWindow) {LogManager.getLogger(this.getClass()).info("Swith to window: " + sWindow);Set<String> contextNames = driver.getContextHandles();LogManager.getLogger(this.getClass()).info("Exists windows: " + contextNames.toString());for (String contextName : contextNames) {if (contextName.contains(sWindow)) {driver.context(contextName);break;}}}switchToWindow("WEBVIEW_com.test.android");driver.findElementByID("wd").sendKeys("test");driver.findElementByID("sub").click();switchToWindow("NATIVE_APP");






Appium - WebView測試(Android)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.