Automating hybrid Apps

Source: Internet
Author: User
Tags appium

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

    1. Navigate to a portion of your apps where a Web view is active
    2. call GET session/:sessionid/contexts
    3. This returns a list of contexts we can access, like ' Native_app ' or ' webview_1 '
    4. call POST Session/:sessionid/context with the "the" context want to access
    5. (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).
    6. 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://"), 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

Related Article

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: 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.