appium 使用findElementByAndroidUIAutomator 定位元素示例
appium 使用findElementByAndroidUIAutomator 定位元素示例
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File;
import java.net.URL;
import java.util.List; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; /**
* Test -android uiautomator locator strategy
*/
public class AndroidUIAutomatorTest { private AppiumDriver driver; @Before
public void setup() throws Exception {
File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} @After
public void tearDown() throws Exception {
driver.quit();
} @Test
public void findElementTest() {
WebElement element = driver.findElementByAndroidUIAutomator("new UiSelector().index(0)");
assertEquals("android.widget.FrameLayout", element.getTagName());
} @Test
public void findElementsTest() {
List<WebElement> elements = driver.findElementsByAndroidUIAutomator("new UiSelector().clickable(true)");
assertTrue(elements.size() > 11);
} @Test
public void findElementByTest() {
WebElement element = driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().index(0)"));
assertEquals("android.widget.FrameLayout", element.getTagName());
} @Test
public void findElementsByTest() {
List<WebElement> elements = driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)"));
assertTrue(elements.size() > 11);
} @Test
public void findChainedElementsTest() {
MobileElement el1 = (MobileElement) driver.findElementByAndroidUIAutomator("resourceId(\"android:id/content\")");
MobileElement el2 = (MobileElement) el1.findElementByAndroidUIAutomator("text(\"Accessibility\")");
el2.click();
MobileElement el3 = (MobileElement) driver.findElementByAndroidUIAutomator("text(\"Custom View\")");
assertTrue(el3.isDisplayed());
} @Test(expected = IllegalArgumentException.class)
public void ErrorTest() {
driver.findElementByAndroidUIAutomator(null);
} }
appium 使用findElementByAndroidUIAutomator 定位元素示例的更多相关文章
- Appium+Python3+iOS定位元素
前言: 最近在做IOS自动化测试,IOS的Appium环境都配置OK,执行起来真的慢,慢到怀疑人生,那么今天就来总结一下IOS定位方式和各个定位方式的速度排序. 据我观察,按查找元素的顺序速度,从快到 ...
- Appium之uiautomator定位元素
元素定位方式有多种,Android也有自身独有的定位方式.下面就单独介绍其基于uiautomator定位元素的方法: 基本语法: driver.find_element_by_android_uiau ...
- Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be fou ...
- Appium之xpath定位元素
原文:http://www.cnblogs.com/cnkemi/p/9180525.html appium也是以webdriver为基的,对于元素的定位也基本一致,只是增加一些更适合移动平台的独特方 ...
- Python+Appium自动化测试(9)-自动选择USB用于传输文件(不依赖appium对手机页面元素进行定位)
一,问题 app自动化测试使用Android真机连接电脑时,通常会遇到两种情况: 1.测试机连接电脑会弹窗提示USB选项,选择USB用于"传输文件",有些手机不支持设置默认USB选 ...
- Appium Python 五:元素定位
总结 单个元素定位: driver.find_element_by_accessibility_id(id) driver.find_element_by_android_uiautomator(ui ...
- Appium学习路—Android定位元素与操作
一.常用识别元素的工具 uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录下 Appium Ins ...
- appium关于定位元素
Windows上定位元素我用的是uiautomatorviewer 这个工具在你的SDK-tools目录下,点击uiautomatorviewer.bat启动,注意appium在跑的时候是取不到的 工 ...
- Appium Android定位元素与操作
文章写得很好,转载备用 一.常用识别元素的工具 uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录 ...
随机推荐
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- 为什么不使用frame框架的原因
框架的优点 重载页面时不需要重载整个页面,只需要重载页面中的一个框架页(减少了数据的传输,增加了网页下载速度) 方便制作导航栏 框架的缺点 会产生很多页面,不容易管理 不容易打印 浏览器的后退按钮无效 ...
- maven发布时在不同的环境使用不同的配置文件
在开发时,不同的环境总会使用到不同的配置.如本地,测试,预发布,发布等环境,像数据库这些都要使用到不同的配置.如果手动改的话肯定会十分的麻烦. 还好maven提供的功能能够帮我们解决这个问题. 我们通 ...
- Objective-C学习篇10—NSDate与NSDateFormatter
NSDate NSDate 时间类,继承自NSObject,其对象表示一个时间点 NSDate *date = [NSDate date]; NSLog(@"date = %@", ...
- 软件测试 homework1
申明数组变量后,在使用的时候,出现了向上溢出的情况(程序运行过程中出现的),导致最后答案不正确,经过输出数组数据发现错误, 现在在申明数组的时候都会大致估算一下,确认申明什么样的数组不会导致溢出. 在 ...
- 手机时间选择插件 Jquery
// 时间选择 var currYear = (new Date()).getFullYear() var opt_data = { preset: 'date', //日期 theme: 'andr ...
- Css3从IE6-IE9的支持查看
http://msdn.microsoft.com/en-us/library/cc351024%28v=vs.85%29.aspx http://caniuse.com/
- OpenStack镜像制作-CentOS
云平台中镜像还是很重要的,提供各种定制化的镜像使得用户体验更好. 最开始玩OpenStack的时候用的是安装文档中提到的cirros,其密码cubswin:) 刚开始感觉很怪,现在已经可以随手打出.p ...
- BufferedReader
Reader FileReader BufferedReader package file; import java.io.BufferedReader; import java.io.File; i ...
- 深度围观block:第三集
深度围观block:第三集 发布于:2013-07-12 10:09阅读数:7804 本文是深度围观block的第三篇文章,也是最后一篇.希望读者阅读了之后,对block有更加深入的理解,同时也希望之 ...