Automating hybrid Apps
One of the core principles of Appium is so you shouldn ' t has to change your app to test it. In line with that methodology, it's possible to test hybrid web apps (e.g., the Uiawebview elements in an IOS app) the SA The Me-i-Can with Selenium for Web apps. There is a bit of technical complexity required so, Appium knows whether you want to automate the native aspects of th E app or the Web views, but thankfully, we can stay within the Webdriver protocol for everything.
Here is the steps required-to-a Web view in your Appium test://testing hybrid Application Steps
- Navigate to a portion of your apps where a Web view is active
- call GET session/:sessionid/contexts
- This returns a list of contexts we can access, like ' Native_app ' or ' webview_1 '
- call POST Session/:sessionid/context with the "the" context want to access
- (This puts your Appium session to a mode where all commands is interpreted as being intended for automating the web View, rather than the native portion of the app. For example, if you run Getelementbytagname, it'll operate on the DOM of the Web view, rather than return uiaelements. Of course, certain webdriver methods only make sense in one context or another, so in the wrong context you'll receive a N error message).
- to stop automating in the Web view context and go automating the native portion of the app, simply call
context
again with the native context ID to leave the Web frame.
1 //Java2 //Assuming we have a set of capabilities3Driver =NewAppiumdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities);4 5Set<string> Contextnames =driver.getcontexthandles ();6 for(String contextname:contextnames) {7System.out.println (Contextnames);//prints out something like Native_app \ n webview_18 }9Driver.context (Contextnames.toarray () [1]);//set context to Webview_1Ten One //Do some Web testing AString MyText = driver.findelement (By.cssselector (". Green_button") . Click (); - -Driver.context ("Native_app"); the - //Do more native testing if we want - -Driver.quit ();
1 #python2 #Assuming we have a initialized ' driver ' object for an app3 4 #Switch to WebView5WebView =Driver.contexts.last6 Driver.switch_to.context (WebView)7 8 #Do some webby stuff9Driver.find_element (: CSS,". Green_button"). ClickTen One #switch back to native view A Driver.switch_to.context (Driver.contexts.first) - - #Do more native testing if we want the -Driver.quit ()
Automating hybrid Android Apps
Appium comes with built-in hybrid support via Chromedriver. Appium also uses selendroid under the hood for WebView support on devices older than 4.4. (In the case, you'll want to specify as "automationName": "selendroid"
a desired capability). //Less than 4.4 of Android versions, need to test hybrid applications with selendroid. The remaining versions are tested by the built-in Chromedriver hybrid application.
Make sure setwebcontentsdebuggingenabled are set to true as described in the Remote debugging docs.
Once you ' ve set your desired capabilities and started an Appium session, follow the generalized instructions above.
Automating hybrid IOS Apps
To interact with a Web view Appium establishes a connection using a remote debugger. When executing against a simulator this connection be established directly as the simulator and the Appium server are on T He same machine. //The iOS emulator on the same computer and Appium server will directly establish a connection.
Once you ' ve set your desired capabilities and started an Appium session, follow the generalized instructions above.
Execution against a real IOS device
When executing against a real IOS device Appium are unable to access the Web view directly. Therefore the connection have to is established through the USB lead. To establish this connection we use the Ios-webkit-debugger-proxy. //ios is connected to Appium server via proxy.
For instruction on what to install and run ios-webkit-debugger-proxy see iOS webkit debug proxy documentation.
Now you can start an Appium test session and follow the generalized instructions above.
Automating hybrid Apps