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)