[uiautomator篇] UiWatcher的使用
//package com.softwinner.pad.mark3d;
package com.softwinner.performance.benchmark.mark3d; import android.content.Context;
import android.content.Intent;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.UiWatcher;
import android.support.test.uiautomator.Until;
import android.util.Log; import com.softwinner.performance.filecopyspeed.TestBase; import org.junit.After;
import org.junit.Before;
import org.junit.Test; import static com.softwinner.performance.benchmark.mark3d.UiAssistant.LAUNCH_TIMEOUT;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat; /**
* mobilexprt2015 performance test
* @author liuzhipeng
*/ public class MobileXPRTTest { private static final String packageName = "com.mobilexprt2015";
private String[] path = {
"/sdcard/performance/mobilexprt/screen/",
"/sdcard/performance/mobilexprt/log/"}; private String logTag = "mobilexprttest";
private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
private UiAssistant cAssistant = new UiAssistant(mDevice,path); private String startButton = "com.mobilexprt2015:id/customize_screen_start_tests";
private String testingObject = "com.mobilexprt2015:id/tv_next_scenario";
private String testendObject = "com.mobilexprt2015:id/group_name"; @Before
public void setUp() throws Exception {
cAssistant.setup(path,logTag);
this.watcherEndTheCall();
} /**
* test mobilexprt performance
* @author liuzhipeng
* @return null
* @throws Exception
*/
@Test
public void testAI030004MobileXPRT() throws Exception
{
int TestNumber = 0;
while(TestNumber < 1){
String assisStr = "[TestNumber_"+TestNumber+"]";
openApplication(packageName);
Log.i(logTag,assisStr+"open mobilexprt ");
Thread.sleep(5000);
// UiObject startTest = mDevice.findObject(new UiSelector().
// resourceId(startButton));
// assertTrue("not found start test button",startTest.exists());
// startTest.clickAndWaitForNewWindow();
// Log.i(logTag,assisStr+"click start test button");
// assertTrue("step[1] fail",cAssistant.WaitforUnitObjectExist(0,testingObject,5,100));
// Log.i(logTag,assisStr+"testing page["+testingObject+ "]exist");
// Thread.sleep(1000*60*1);
// assertTrue("step[2] fail",cAssistant.WaitforUnitObjectExist(0,testendObject,17*60,500));
// Log.i(logTag,assisStr+"test end page["+testendObject+"]exist");
// cAssistant.takescreen("mobilexprt[TestNumber_"+TestNumber +"]End",
// "[TestNumber_"+TestNumber +"]mobilexprtScore");
// Log.i(logTag,assisStr+"test end,and takescreen");
cAssistant.QuitApplication(packageName);
Log.i(logTag,assisStr+"quit mobilexprt");
Thread.sleep(1000*10);
TestNumber++; } }
public void openApplication(String packName) throws RemoteException {
mDevice.wakeUp();
/* Start from the home screen*/
mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName();
assertThat(launcherPackage,notNullValue());
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
LAUNCH_TIMEOUT); // launch the app
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(packName);
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent); // Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(packName).depth(0)),
LAUNCH_TIMEOUT);
}
private void watcherEndTheCall(){
// UiDevice 动作不会触发监听器
// runWatcher是在查找控件失败时会调用,当然你也可以自己调用
// findAccessibilityNodeInfo里面会调用runWatcher
// UiObject.findAccessibilityNodeInfo,查找控件会用到
mDevice.registerWatcher("endCallWatcher", new UiWatcher() {
UiObject incomingCall = mDevice.findObject(new UiSelector()
.resourceId(""));
@Override
public boolean checkForCondition() {
System.out.println("endCallWatcher running");
if(incomingCall.exists()){
try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}
System.out.println("endCall success");
return true;
}
System.out.println("endCall fail");
return false;
}
});
}
@After
public void tearDown() throws Exception {
Log.i(logTag,"is triggered :"+ mDevice.hasWatcherTriggered("endCallWatcher"));
mDevice.removeWatcher("endCallWatcher"); }
}
[uiautomator篇] UiWatcher的使用的更多相关文章
- [uiautomator篇]uiwatcher 的使用场景
http://www.yangyanxing.com/article/use-watcher-in-uiautomator.html 今天在uiautomator中实践了watcher的用法,这个 ...
- [uiautomator篇][1] 官网译文
http://www.jianshu.com/p/7718860ec657 2016.07.25 20:59 字数 3675 Android UIAutomator浅谈 --------------- ...
- [uiautomator篇] 基类
package com.softwinner.performance.benchmark; /** * UiAssistant public class * @author liuzhipeng ...
- [uiautomator篇][exist 存在,但click错误]
uiautomator定位页面元素是,定位存在的;但是click的时候,发现点的位置不对,(不知道是android系统的问题还是uiautomator的问题,初步怀疑是系统的问题)
- [uiautomator篇] 使用uiautomator需要导入uiautomator库
1 修改依赖文件:build/gradle( 是在app目录下)而不是和app同级目录的build/gradle androidTestCompile 'com.android.support.tes ...
- [Uiautomator篇][2] UiDeviceAPI介绍
1 https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html http://www.cnb ...
- [UiAutomator篇][3] 打开音乐应用的测试脚本
package qq.test; import android.content.Context; import android.content.Intent; import android.suppo ...
- [uiautomator篇]recent
def Recent(self): d = Device('9410519008004c22098b') displayWidth = int(d.info.get("displayWidt ...
- [uiautomator篇] python uiautomatorDemo
#coding=utf-8 """ @version: 1.0 @author: @prerequisite: based on Python 2.7 @usage: 1 ...
随机推荐
- 用vue.js重构订单计算页面
在很久很久以前做过一个很糟糕的订单结算页面,虽然里面各区域(收货地址)使用模块化加载,但是偶尔会遇到某个模块加载失败的问题导致订单提交的数据有误. 大致问题如下: 1. 每个模块都采用usercont ...
- Java开发笔记(九十六)线程的基本用法
每启动一个程序,操作系统的内存中通常会驻留该程序的一个进程,进程包含了程序的完整代码逻辑.一旦程序退出,进程也就随之结束:反之,一旦强行结束进程,程序也会跟着退出.普通的程序代码是从上往下执行的,遇到 ...
- AJPFX关于线程创建的方式
创建线程的第一种方式:继承Thread ,由子类复写run方法. 步骤: 1,定义类继承Thread类: 2,目的是复写run方法,将要让线程运行的代码都存储到run方法中: 3,通过创建Thread ...
- kafka系列一:单节点伪分布式集群搭建
Kafka集群搭建分为单节点的伪分布式集群和多节点的分布式集群两种,首先来看一下单节点伪分布式集群安装.单节点伪分布式集群是指集群由一台ZooKeeper服务器和一台Kafka broker服务器组成 ...
- 【学习笔记】六:面向对象的程序设计——理解JS中的对象属性、创建对象、JS中的继承
ES中没有类的概念,这也使其对象和其他语言中的对象有所不同,ES中定义对象为:“无序属性的集合,其属性包含基本值.对象或者函数”.现在常用的创建单个对象的方法为对象字面量形式.在常见多个对象时,使用工 ...
- github入门之分支操作--5
1.显示分一览表 2.创建.切换分支 2.1.切换到feature-A分支并进行提交 2.1.1.执行下面的命令,创建名为feature-A的分支 实际上,执行以命令也能收到同样的效果,但是我习惯使用 ...
- codevs 2915 期末考试
时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description 期末考试要来了,某同学正在努力复习. 他要复习N个知识点,每个知识点需要一定的知识 ...
- iOS的设计备忘录/资源集合(新手快速开发)
iOS的设计备忘录 随着iOS7更新,风格走上扁平化,大部分iOS设计师及程序员都需要对自己的软件做相关调整,尺寸.Icon.UI等等,我在这里总结一下相关资料,以及提供一些关于iOS7设计素材. 一 ...
- WPF中在后台实现控件样式
加入现在有一个Button的样式如下: <Style TargetType="{x:Type Button}" x:Key="MyButton">. ...
- winform中让显示的图片覆盖到父窗体保持父窗体的不可选中的状态,且任务栏中不会显示子窗体的任务选项
要求:为父窗体添加一个类似于加载等待的功能,当窗体点击备份时弹出且覆盖掉窗体 问题一产生:当为弹窗添加控件时,form.show();导致窗体卡死,控件变得透明化; 问题一分析:当窗体show();之 ...