android自动化测试6-UIAutomator黑盒测试2
来源:互联网 发布:微聊客软件 编辑:程序博客网 时间:2024/06/16 20:38
上一篇我们介绍了一个简单的UIAutomator测试,模拟了press home键回到主界面,现在我们来对一个指定的app做测试,关于如何创建UIAutomator工程请参考上一篇,这里我们以前面的android工程AndroidCalculator为例。
Android SDK从4.1开始提供了如下两个工具来支持UI自动化测试:
uiautomatorviewer – 一个图形界面工具来扫描和分析应用的UI控件。
uiautomator – 一个测试的Java库,包含了创建UI测试的各种API和执行自动化测试的引擎。
前面我们已经使用了uiautomator的库,现在我们需要使用uiautomatorviewer来分析控件,以供自动化测试。
1,打开模拟器,打开AndroidCalcualor程序
2,打开命令行,运行uiautomatorviewer,uiautomatorviewer在android sdk 的tool文件夹下
3,点击左上角的device screenshot键,可以取出当前界面的各个元素
从中可以看出第一个乘数所在的EditText在界面中的index是2,
所以我们在测试代码中可以通过new UiObject(new UiSelector().index(2))得到它的对象,之后就可以对该对象通过setText做赋值操作。同理我们可以得到其它的对象。
4,现在我们来写测试用例,输入10到第一个乘数,输入20到第二个乘数,然后点击Multiply,最后验证结果是否正确。
简单处理,我们只需把上文的testcase改一改就可以了:
public class Demo1 extends UiAutomatorTestCase {
public void testDemo1() throws UiObjectNotFoundException {
// // Simulate a short press on the HOME button.
// getUiDevice().pressHome();
new UiObject(new UiSelector().index(2)).setText("10");
new UiObject(new UiSelector().index(4)).setText("20");
new UiObject(new UiSelector().index(7)).click();
Assert.assertEquals("200", new UiObject(new UiSelector().index(6)).getText());
}
}
5,接下来的ant编译,push jar到device,运行uiautomator测试请参看上一篇。
- android自动化测试6-UIAutomator黑盒测试2
- android自动化测试5-UIAutomator黑盒测试
- android uiautomator自动化测试
- UiAutomator android自动化测试
- Android-自动化测试UIAutomator
- Android自动化测试uiautomator
- Android UiAutoMator自动化测试
- Android Uiautomator 自动化测试
- Android Uiautomator 自动化测试
- Android自动化测试之UIAutomator
- Android自动化测试(UiAutomator)
- Android自动化测试工具uiautomator
- Python + Android + Uiautomator自动化测试
- Android自动化测试之UIAutomator
- Python + Android + Uiautomator自动化测试
- android uiautomator自动化测试记录
- Android自动化测试(UiAutomator)
- Android UiAutomator & UiAutomatorViewer 自动化测试
- C语言---给定年、月、日,输出其为这一年的第几天(多版本)
- ubuntu 设置系统环境变量
- HDU 1.3.3 开门人和关门人
- 偶然发现一个linux资源网站
- 朴淳 思庵 欲掩其跡
- android自动化测试6-UIAutomator黑盒测试2
- Ubuntu下配置samba实现文件夹共享
- 事件处理程序WinProc
- 初级计算器算法(栈处理运算符优先级)
- Ural 2018The Debut Album(DP)
- 组建局域网时常用的拓扑结构
- 微软数据结构+算法面试100题首次完整亮相
- IS_ERR()说明
- 我的第一个C++程序