[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 ...
随机推荐
- Java设计模式开篇
在所有的设计模式开篇中,总是说一个好的架构,或多或少都会有设计模式的出现.当然或多或少也会使用设计模式的相关原则: SOLID+迪米尔原则 1.优化代码的第一步:单一职责原则 S:单一职责链原则:英文 ...
- 日常博客-png,jpeg,gif图片
个人博客记录:2017-11-09 png-----32位无损压缩算法形成的图片,主要用于logo小图标和一些点缀的小图像.放大缩小不会失真,质量好 jpeg,jpg-----压缩比例较高(可达到10 ...
- java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/xxx/lib/arm/liblame.so: has text relocations
最近在写本地录音转码过程中引入了liblame.so,我这边用了不同系统版本的手机测试本地录音都没有出现问题,但是有一天,同事在测试的时候,出现了以下错误: 09-13 17:32:29.140 26 ...
- 1、Centos7 python2.7和yum完全卸载及重装
完全重装python和yum 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1.删除现有Python ...
- linux各文件夹的作用(转)
转自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可 ...
- Yii2中多表关联查询(with、join、joinwith)
表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_name custome ...
- 一次性删除数据库所有表和所有存储过程 SQL语句
一次性删除数据库所有表和所有存储过程 SQL语句 今天转移数据库数据,需要把数据库原来的表和存储过程清空.删除所有的表:如果由于外键约束删除table失败,则先删除所有约束: --/第1步****** ...
- 05_Python格式化打印
一般框架 tplt = '' #格式化模板 print(tplt.format(…)) #填充内容 tplt = '{0}-{1}+{2}={3}' {}表示了一个槽,槽里面的内容使用key:valu ...
- Python进程间通信和网络基础
Python进程间通信和网络基础 Python支持多种进程间通讯的方式, 有单机通信的signal和mmap等, 也有可以通过网络的socket方式, 这里先介绍select等的有关知识, socke ...
- LVM逻辑分区的优缺点与步骤
一.LVM简介 1. 什么是LVM? LVM是 Logical Volume Manager(逻辑卷管理)的简写 2. 为什么使用LVM? LVM通常用于装备大量磁盘的系统,但它同样适于仅有一.两块硬 ...