Automating hybrid apps
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://测试混合应用的步骤
- Navigate to a portion of your app 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 id of the context you want to access
- (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).
- 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的更多相关文章
- 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 ...
- Multi-Device Hybrid Apps (Preview)
Today, we released a preview of Visual Studio tooling support for Apache Cordova http://msdn.microso ...
- app hybrid
package com.note.testcases; /** * * The MIT License (MIT) * * Copyright (c) 2016 Alejandro Gómez Mor ...
- Native Apps、Web Apps
Native Apps 指的是远程程序,一般依托于操作系统,有很强的交互,是一个完整的App,可拓展性强,需要用户下载安装使用 优点: 打造完美的用户体验 性能稳定 操作速度快,上手流畅 访问本地资源 ...
- appium简明教程
appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...
- appium简明教程(1)——appium和它的哲学世界
什么是appium? 本文已经迁移到测试教程网,后续更新会在测试教程网更新. 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use ...
- UI“三重天”之appium(一)
官方介绍: Appium is an open-source tool for automating native, mobile web, and hybrid applications on iO ...
- 转: Appium ---移动自动化测试
转自:http://www.cnblogs.com/nbkhic/p/3803830.html 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-sou ...
- appium(1)-about appium
about appium Introduction to Appium Appium is an open-source tool for automating native, mobile web, ...
随机推荐
- Struts2的上传与下载
转自:http://blog.csdn.net/Mark_LQ/article/details/49822821 10.1.1 文件上传基本案例 第一步:上传组件依赖与commons-fileup ...
- AC日记——网络最大流 洛谷 P3376
题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行 ...
- ListView+EditText使用遇到的坑
最近项目中某功能需要ListView嵌套EditText来实现,使用过程中遇到一些问题: 1.点击弹出编辑框,edittext会失去焦点. 解决焦点丢失的问题 解决思路:软键盘弹出的时候会重新绘制界面 ...
- linux编译
文章一 1)用户点击编译程序时,编译程序将C++源代码转换成目标代码,目标代码通常由 机器指令和记录如何将程序加载到内存的信息组成.其后缀通常为.obj或.o: 2)目标文件中存储的只是用户所编写的代 ...
- 济南day3
连续几天都有点炸 预计的分拿不到,调整好心态,考试的时候多想一下,think twice,code once 唉,什么情况啊 题解链接 0+0+0 T1读错题输出反了 n*m%2判断是否==1 T2 ...
- 1.搭建maven,eclipse创建maven项目
1.下载maven包,下载地址为:http://maven.apache.org/download.cgi 2.解压zip包 3.eclipse 引入maven: window-Preferences ...
- Ubuntu 16.04中的Dock的应用顺序调整
操作步骤: 参考: https://askubuntu.com/questions/39805/is-there-an-easy-way-to-rearrange-or-move-the-icons- ...
- SQL-基础学习2--ORDER BY ,DESC,WHERE, BETWEEN,AND ,OR ,IN ,NOT
所使用的数据库资料在:数据库资料 第三课:排序检索数据 3.1 排序数据 按单列排序 如果不排序,数据一般将以它在底层表中出现的顺序显示,这有可能是数据最初添加到表中的顺序.但是,如果数据随后进行 ...
- Android 检查输入
在开发过程中,会经常遇到这样的需求:上面有很多的输入控件,等所有的输入都合法后,按钮才能自动变成enabled的状态,才能继续下一步的操作. 下面是一种用观察者模式实现的一种解决方案. button代 ...
- linux 中两个文档怎么对比内容是否一致
可以用diff命令对比文档内容.[语法]: diff [参数] 文件1 文件2[说明]: 本命令比较两个文本文件,将不同的行列出来-b 将一串空格或TAB 转换成一个空格或TAB-e 生成一个编辑角本 ...