Appium测试混合应用

混合应用即是原生应用中间混着html页面,需要在两种类型的页面之间跳转。

测试Android混合应用

前期设置

  1. 4.4以下版本使用automationName:Selendroid
  2. 4.4及其以上的版本使用automationName:Appium
  3. 需要设置webview的debug模式为true,默认是false

元素定位

Selendroid模式:selendroid inspector

Appium模式:chrome://inspect

代码示例

设置webview的debug模式,需要插入在android源码当中:

if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT){
WebView.setWebContentsDebuggingEnabled(true);
}

Selendroid代码示例,appium模式替换automationName:Appium即可:

//配置 webdriver 并启动 webview 应用。
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("device", "Selendroid");
desiredCapabilities.setCapability("app", "/path/to/some.apk");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities); // 切换到最新的web视图
remoteWebDriver.switchTo().window("WEBVIEW"); //在 guinea-pig 页面用 id 和 元素交互。
WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
Assert.assertEquals("I am a div", div.getText()); //验证得到的文本是否正确。
remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //填写评论。 //离开 webview,回到原生应用。
remoteWebDriver.switchTo().window("NATIVE_APP"); //关闭应用。
remoteWebDriver.quit();

测试iOS混合应用

前期设置

  1. 模拟器和本地应用相同
  2. 测试真机时需要ios_webkit_debug_proxy工具
brew install ios_webkit_debug_proxy

ios_webkit_debug_proxy -c [udid]:27753 -d

元素定位

使用Safari或者chrome的开发者工具

代码示例

//配置 webdriver 并启动 webview 应用。
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("device", "iPhone Simulator");
desiredCapabilities.setCapability("app", "http://appium.s3.amazonaws.com/WebViewApp6.0.app.zip");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities); // 切换到最新的web视图
for(String context : driver.getContextHandles()){
if (context.contains("WEBVIEW")) {
driver.context(context);
}
} //在 guinea-pig 页面用 id 和 元素交互。
WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
Assert.assertEquals("I am a div", div.getText()); //验证得到的文本是否正确。
remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //填写评论。 //离开 webview,回到原生应用。
remoteWebDriver.executeScript("mobile: leaveWebView"); //关闭应用。
remoteWebDriver.quit();

参考官方文档

Appium混合应用测试的更多相关文章

  1. appium 真机测试问题 出现 instruments crashed on startup

    1.appium 真机测试的时候 instruments crashed on startup,必须在真机上打开UI Automation 在设置里: Developer->Enable UI ...

  2. DevOps on DevCloud|如何实现应用接口的混合驱动测试

    引言:在"DevOps能力之屋(Capabilities House of DevOps)"中,华为云DevCloud提出(工程方法+最佳实践+生态)×工具平台=DevOps能力. ...

  3. Appium Hybrid混合应用测试——Native切换WebView

    Appium Hybrid混合应用测试过程中,经常需要在Native和WebView之间进行切换: 1.切换至WEBVIEW操作: for cons in driver.contexts: if co ...

  4. Appium Hybrid混合应用测试——Native切换WebView , 切换不了WebView (没有试过,先记录在此)

    Appium Hybrid混合应用测试过程中,经常需要在Native和WebView之间进行切换: 1.切换至WEBVIEW操作: for cons in driver.contexts: if co ...

  5. 使用appium进行ios测试,启动inspector时遇到的问题(一)

    最近在公司,让做ios的自动化测试,因为以前做过android的自动化测试,用的也是appium,觉得没什么,结果一开始在搭建环境就遇到了很多的问题,现在将我遇到的问题,以及解决方法,给大家分享出来. ...

  6. 使用Selenium+appium进行App测试

    1. 启动安卓虚拟机.

  7. 三 APPIUM Android自动化 测试初体验

    1.创建一个maven项目 成功新建工程: 编辑pom.xml,在<dependencies></dependencies>下添加appium相关依赖: <depende ...

  8. appium执行iOS测试脚本并发问题

    appium1.4.X+iOS9.X+xcode7.X: appium1.4.x+iOS9.x+xcode7.x,这一整套的配置做移动端自动化测试是测试人员常用的测试框架.关于,这一套测试框架的并发问 ...

  9. 6-3-2绕过appium的iOS测试

    WDA自带的inspector 1.启动WDA Xcode启动:product-test,适合个人调试 命令行启动:适合持续集成 UDID=$(idevice_id -l) xcodebuild -p ...

随机推荐

  1. gitlab pipelines 使用

    1. 安装runner   # For Debian/Ubuntu curl -L https://packages.gitlab.com/install/repositories/runner/gi ...

  2. sourcetree 分支的创建合并

    sourcetree 分支的创建合并,提交 https://blog.csdn.net/qq_34975710/article/details/74469068 sourcetree测试版本的配置忽略 ...

  3. 【转】使用JMeter 完成常用的压力测试(三)

    使用JMeter 完成常用的压力测试 发布时间: 2008-9-27 15:33    作者: 未知    来源: 网络转载 字体:  小  中  大  | 上一篇 下一篇 | 打印  | 我要投稿 ...

  4. MySQL存储过程中的3种循环,存储过程的基本语法,ORACLE与MYSQL的存储过程/函数的使用区别,退出存储过程方法

    在MySQL存储过程的语句中有三个标准的循环方式:WHILE循环,LOOP循环以及REPEAT循环.还有一种非标准的循环方式:GOTO,不过这种循环方式最好别用,很容易引起程序的混乱,在这里就不错具体 ...

  5. Excel开发学习笔记:查找与创建worksheet

    开发环境基于VSTO,具体配置:visual studio 2010,VB .Net,excel 2007,文档级别的定制程序. 如题,我在ThisWorkbook.vb中添加了一个public函数来 ...

  6. Python下OS模块重命名方法renames

    在python中有很多强大的模块,其中我们经常要使用的就是OS模块,OS模块提供了超过200个方法来供我们使用,并且这些方法都是和数据处理相关的,这里介绍下重命名这个方法. OS的重命名方法是os.r ...

  7. 恒创科技 基于openStack云主机

    https://www.henghost.com/cloud-vps.shtml?s=gg&gclid=CKaXuOyr79UCFY-TvQodMJ8BCw

  8. 动态规划——最长不下降子序列(LIS)

    最长不降子序列是这样一个问题: 下面介绍动态规划的做法. 令 dp[i] 表示以 A[i] 结尾的最长不下降序列长度.这样对 A[i] 来说就会有两种可能: 如果存在 A[i] 之前的元素 A[j] ...

  9. Python编程总结之常用三方模块

    1.excel读写 利用python进行excel读写是经常遇到的事情,最常用的excel读写模块必属xlrd和xlwt,前者负责读,后者负责写,配合起来可实现读写. 举例1):使用xlrd读取exc ...

  10. linux中stdout,stdin,stderr意义

    stdout, stdin, stderr的中文名字分别是标准输出,标准输入和标准错误. 在Linux下,当一个用户进程被创建的时候,系统会自动为该进程创建三个数据流,也就是题目中所提到的这三个.那么 ...