Appium-webview Test (Android)

Source: Internet
Author: User
Tags appium

Appium-webview Test

Author: Max.bai

Time: 2015/07



Appium-webview Test (Android)

Today's apps are all mixed-type. There are native also including WebView, Appium test when you need to switch between the original and webview the ability to complete the test.


1. View all context

View all the current forms

set<string> contextnames = Driver.getcontexthandles (); System.print (Contextnames);
The results include all the apps that are open right now, like I've opened Es, my tested application, and another application,

[Native_app, WEBVIEW_com.test.android, WEBVIEW_com.estrongs.android.pop, WEBVIEW_COM.XXXXX.SJJ]

Native_app is my application-native interface

WEBVIEW_com.test.android is my application opened WEBVIEW

The other two are ES, one other application (mixed type)


2. Switch to WebView

Get all the current context through the above method

We can switch to the specified application through the context method

<pre name= "code" class= "Java" >driver.context ("WEBVIEW_com.test.android");d River.findelementbyid ("WD");

After switching, you can test the same as a Web application, with all the same positioning as the web.

3. Switch to Nativeapp

After testing Web applications, you need to switch back to Native_app when you need to operate native applications.

We can switch to the native app via the context method

<pre name= "code" class= "Java" >driver.context ("Native_app");
This will be the operation of the native application.

4. Demo

/** * Switch to Native_app or WEBVIEW * @param swindow window name */private void Switchtowindow (String swindow) {Logmanag Er.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");d River.findelementbyid ("WD"). SendKeys ("test"); Driver.findelementbyid ("Sub"). Click (); Switchtowindow ("Native_app");






Appium-webview Test (Android)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.