Automating hybrid apps

One of the core principles of Appium is that you shouldn’t have to change your app to test it. In line with that methodology, it is possible to test hybrid web apps (e.g., the UIAWebView elements in an iOS app) the same way you can with Selenium for web apps. There is a bit of technical complexity required so that Appium knows whether you want to automate the native aspects of the app or the web views, but thankfully, we can stay within the WebDriver protocol for everything.

Here are the steps required to talk to a web view in your Appium test://测试混合应用的步骤

  1. Navigate to a portion of your app 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 id of the context you want to access
  5. (This puts your Appium session into a mode where all commands are interpreted as being intended for automating the web view, rather than the native portion of the app. For example, if you run getElementByTagName, it will 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 will receive an error message).
  6. To stop automating in the web view context and go back to automating the native portion of the app, simply call context again with the native context id to leave the web frame.
 // java
// assuming we have a set of capabilities
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1 //do some web testing
String myText = driver.findElement(By.cssSelector(".green_button")).click(); driver.context("NATIVE_APP"); // do more native testing if we want driver.quit();
 # python
# assuming we have an initialized `driver` object for an app # switch to webview
webview = driver.contexts.last
driver.switch_to.context(webview) # do some webby stuff
driver.find_element(:css, ".green_button").click # switch back to native view
driver.switch_to.context(driver.contexts.first) # do more native testing if we want 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 that case, you’ll want to specify "automationName": "selendroid" as a desired capability).//低于4.4的安卓版本,需要用Selendroid测试混合应用。其余的版本,通过内置的Chromedriver测试混合应用。

Make sure setWebContentsDebuggingEnabled is 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 is established directly as the simulator and the appium server are on the same machine.//同一个电脑上的iOS模拟器与appium server会直接建立连接。

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 is unable to access the web view directly. Therefore the connection has to be established through the USB lead. To establish this connection we use the ios-webkit-debugger-proxy.//iOS真机通过代理与appium server取得连接。

For instruction on how 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的更多相关文章

  1. Multi-Device Hybrid Apps for Visual Studio CTP2.0

    http://msdn.microsoft.com/en-us/library/dn771545.aspx http://www.microsoft.com/en-us/download/detail ...

  2. Multi-Device Hybrid Apps (Preview)

    Today, we released a preview of Visual Studio tooling support for Apache Cordova http://msdn.microso ...

  3. app hybrid

    package com.note.testcases; /** * * The MIT License (MIT) * * Copyright (c) 2016 Alejandro Gómez Mor ...

  4. Native Apps、Web Apps

    Native Apps 指的是远程程序,一般依托于操作系统,有很强的交互,是一个完整的App,可拓展性强,需要用户下载安装使用 优点: 打造完美的用户体验 性能稳定 操作速度快,上手流畅 访问本地资源 ...

  5. appium简明教程

    appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...

  6. appium简明教程(1)——appium和它的哲学世界

    什么是appium? 本文已经迁移到测试教程网,后续更新会在测试教程网更新. 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use ...

  7. UI“三重天”之appium(一)

    官方介绍: Appium is an open-source tool for automating native, mobile web, and hybrid applications on iO ...

  8. 转: Appium ---移动自动化测试

    转自:http://www.cnblogs.com/nbkhic/p/3803830.html 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-sou ...

  9. appium(1)-about appium

    about appium Introduction to Appium Appium is an open-source tool for automating native, mobile web, ...

随机推荐

  1. Day 16 之二 省市县三级联动

    摘录自:雨神,供参考! province_dic = { "河北": { "石家庄": ["鹿泉", "藁城", &qu ...

  2. AC日记——Super Mario hdu 4417

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. PHP实现自定义中奖和概率算法

    最近玩<QQ飞车手游>,出了一款点券A车,需要消耗抽奖券抽奖,甚是激动,于是抽了几次,没想到中的都是垃圾道具,可恨可叹~~ 这几天项目中也涉及到了类似的概率操作,于是思考了一下,简单分装了 ...

  4. HDU 4912 Paths on the tree(LCA+贪心)

    题目链接 Paths on the tree 来源  2014 多校联合训练第5场 Problem B 题意就是给出m条树上的路径,让你求出可以同时选择的互不相交的路径最大数目. 我们先求出每一条路径 ...

  5. Redis实用监控工具一览

    Redis已经成为web应用开发不可或缺的一个组成部分,在项目中的应用越来越广泛,这篇文章就来讲讲那些关于Redis监控的那点事. vredis-benchmark 1.1 简介 第一个就介绍一下,R ...

  6. Mac item2 配色,大小写敏感及常用快捷键

    http://blog.csdn.net/lainegates/article/details/38313559 目录(?)[-] 配色 大小写敏感 快捷揵   item2是mac下非常好用的一款终端 ...

  7. 【hibernate】hibernate和mybatis的比较

    理解和学习,使自己在做项目中更加得心应手. 第一方面:开发速度的对比就开发速度而言,Hibernate的真正掌握要比Mybatis来得难些.Mybatis框架相对简单很容易上手,但也相对简陋些.个人觉 ...

  8. DevExpress右键菜单使用 z

    添加BarManager和popupMenu组建: 设置popupMenu组件的Manager属性: 右键点击popupMenu主键,点击Customize选项添加菜单:    然后便可添加到鼠标事件 ...

  9. cocos2d-x step by step(3) Doub le Kill简单的一些小动画

    在触控厮混了两年多,不过达到了自己的初衷以及目的. 目前从事cocos2d的更改和调优移植工作. 1 简单的一个图片放大和缩小 auto sprite = Sprite::create("l ...

  10. DLL注入新姿势:反射式DLL注入研究

    在分析koadic渗透利器时,发现它有一个注入模块,其DLL注入实现方式和一般的注入方式不一样.搜索了一下发现是由HarmanySecurity的Stephen Fewer提出的ReflectiveD ...