1. //package com.softwinner.pad.mark3d;
  2. package com.softwinner.performance.benchmark.mark3d;
  3.  
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.RemoteException;
  7. import android.support.test.InstrumentationRegistry;
  8. import android.support.test.uiautomator.By;
  9. import android.support.test.uiautomator.UiDevice;
  10. import android.support.test.uiautomator.UiObject;
  11. import android.support.test.uiautomator.UiSelector;
  12. import android.support.test.uiautomator.UiWatcher;
  13. import android.support.test.uiautomator.Until;
  14. import android.util.Log;
  15.  
  16. import com.softwinner.performance.filecopyspeed.TestBase;
  17.  
  18. import org.junit.After;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21.  
  22. import static com.softwinner.performance.benchmark.mark3d.UiAssistant.LAUNCH_TIMEOUT;
  23. import static junit.framework.Assert.assertTrue;
  24. import static org.hamcrest.core.IsNull.notNullValue;
  25. import static org.junit.Assert.assertThat;
  26.  
  27. /**
  28. * mobilexprt2015 performance test
  29. * @author liuzhipeng
  30. */
  31.  
  32. public class MobileXPRTTest {
  33.  
  34. private static final String packageName = "com.mobilexprt2015";
  35. private String[] path = {
  36. "/sdcard/performance/mobilexprt/screen/",
  37. "/sdcard/performance/mobilexprt/log/"};
  38.  
  39. private String logTag = "mobilexprttest";
  40. private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
  41. private UiAssistant cAssistant = new UiAssistant(mDevice,path);
  42.  
  43. private String startButton = "com.mobilexprt2015:id/customize_screen_start_tests";
  44. private String testingObject = "com.mobilexprt2015:id/tv_next_scenario";
  45. private String testendObject = "com.mobilexprt2015:id/group_name";
  46.  
  47. @Before
  48. public void setUp() throws Exception {
  49. cAssistant.setup(path,logTag);
  50. this.watcherEndTheCall();
  51. }
  52.  
  53. /**
  54. * test mobilexprt performance
  55. * @author liuzhipeng
  56. * @return null
  57. * @throws Exception
  58. */
  59. @Test
  60. public void testAI030004MobileXPRT() throws Exception
  61. {
  62. int TestNumber = 0;
  63. while(TestNumber < 1){
  64. String assisStr = "[TestNumber_"+TestNumber+"]";
  65. openApplication(packageName);
  66. Log.i(logTag,assisStr+"open mobilexprt ");
  67. Thread.sleep(5000);
  68. // UiObject startTest = mDevice.findObject(new UiSelector().
  69. // resourceId(startButton));
  70. // assertTrue("not found start test button",startTest.exists());
  71. // startTest.clickAndWaitForNewWindow();
  72. // Log.i(logTag,assisStr+"click start test button");
  73. // assertTrue("step[1] fail",cAssistant.WaitforUnitObjectExist(0,testingObject,5,100));
  74. // Log.i(logTag,assisStr+"testing page["+testingObject+ "]exist");
  75. // Thread.sleep(1000*60*1);
  76. // assertTrue("step[2] fail",cAssistant.WaitforUnitObjectExist(0,testendObject,17*60,500));
  77. // Log.i(logTag,assisStr+"test end page["+testendObject+"]exist");
  78. // cAssistant.takescreen("mobilexprt[TestNumber_"+TestNumber +"]End",
  79. // "[TestNumber_"+TestNumber +"]mobilexprtScore");
  80. // Log.i(logTag,assisStr+"test end,and takescreen");
  81. cAssistant.QuitApplication(packageName);
  82. Log.i(logTag,assisStr+"quit mobilexprt");
  83. Thread.sleep(1000*10);
  84. TestNumber++;
  85.  
  86. }
  87.  
  88. }
  89. public void openApplication(String packName) throws RemoteException {
  90. mDevice.wakeUp();
  91. /* Start from the home screen*/
  92. mDevice.pressHome();
  93.  
  94. final String launcherPackage = mDevice.getLauncherPackageName();
  95. assertThat(launcherPackage,notNullValue());
  96. mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
  97. LAUNCH_TIMEOUT);
  98.  
  99. // launch the app
  100. Context context = InstrumentationRegistry.getContext();
  101. final Intent intent = context.getPackageManager()
  102. .getLaunchIntentForPackage(packName);
  103. // Clear out any previous instances
  104. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  105. context.startActivity(intent);
  106.  
  107. // Wait for the app to appear
  108. mDevice.wait(Until.hasObject(By.pkg(packName).depth(0)),
  109. LAUNCH_TIMEOUT);
  110. }
  111. private void watcherEndTheCall(){
  112. // UiDevice 动作不会触发监听器
  113. // runWatcher是在查找控件失败时会调用,当然你也可以自己调用
  114. // findAccessibilityNodeInfo里面会调用runWatcher
  115. // UiObject.findAccessibilityNodeInfo,查找控件会用到
  116. mDevice.registerWatcher("endCallWatcher", new UiWatcher() {
  117. UiObject incomingCall = mDevice.findObject(new UiSelector()
  118. .resourceId(""));
  119. @Override
  120. public boolean checkForCondition() {
  121. System.out.println("endCallWatcher running");
  122. if(incomingCall.exists()){
  123. try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}
  124. System.out.println("endCall success");
  125. return true;
  126. }
  127. System.out.println("endCall fail");
  128. return false;
  129. }
  130. });
  131. }
  132. @After
  133. public void tearDown() throws Exception {
  134. Log.i(logTag,"is triggered :"+ mDevice.hasWatcherTriggered("endCallWatcher"));
  135. mDevice.removeWatcher("endCallWatcher");
  136.  
  137. }
  138. }

[uiautomator篇] UiWatcher的使用的更多相关文章

  1. [uiautomator篇]uiwatcher 的使用场景

    http://www.yangyanxing.com/article/use-watcher-in-uiautomator.html   今天在uiautomator中实践了watcher的用法,这个 ...

  2. [uiautomator篇][1] 官网译文

    http://www.jianshu.com/p/7718860ec657 2016.07.25 20:59 字数 3675 Android UIAutomator浅谈 --------------- ...

  3. [uiautomator篇] 基类

      package com.softwinner.performance.benchmark; /** * UiAssistant public class * @author liuzhipeng ...

  4. [uiautomator篇][exist 存在,但click错误]

    uiautomator定位页面元素是,定位存在的;但是click的时候,发现点的位置不对,(不知道是android系统的问题还是uiautomator的问题,初步怀疑是系统的问题)

  5. [uiautomator篇] 使用uiautomator需要导入uiautomator库

    1 修改依赖文件:build/gradle( 是在app目录下)而不是和app同级目录的build/gradle androidTestCompile 'com.android.support.tes ...

  6. [Uiautomator篇][2] UiDeviceAPI介绍

    1 https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html  http://www.cnb ...

  7. [UiAutomator篇][3] 打开音乐应用的测试脚本

    package qq.test; import android.content.Context; import android.content.Intent; import android.suppo ...

  8. [uiautomator篇]recent

    def Recent(self): d = Device('9410519008004c22098b') displayWidth = int(d.info.get("displayWidt ...

  9. [uiautomator篇] python uiautomatorDemo

    #coding=utf-8 """ @version: 1.0 @author: @prerequisite: based on Python 2.7 @usage: 1 ...

随机推荐

  1. Java设计模式开篇

    在所有的设计模式开篇中,总是说一个好的架构,或多或少都会有设计模式的出现.当然或多或少也会使用设计模式的相关原则: SOLID+迪米尔原则 1.优化代码的第一步:单一职责原则 S:单一职责链原则:英文 ...

  2. 日常博客-png,jpeg,gif图片

    个人博客记录:2017-11-09 png-----32位无损压缩算法形成的图片,主要用于logo小图标和一些点缀的小图像.放大缩小不会失真,质量好 jpeg,jpg-----压缩比例较高(可达到10 ...

  3. java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/xxx/lib/arm/liblame.so: has text relocations

    最近在写本地录音转码过程中引入了liblame.so,我这边用了不同系统版本的手机测试本地录音都没有出现问题,但是有一天,同事在测试的时候,出现了以下错误: 09-13 17:32:29.140 26 ...

  4. 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 ...

  5. linux各文件夹的作用(转)

    转自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可 ...

  6. Yii2中多表关联查询(with、join、joinwith)

    表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer   (id  customer_name) 订单表Order         (id  order_name   custome ...

  7. 一次性删除数据库所有表和所有存储过程 SQL语句

    一次性删除数据库所有表和所有存储过程 SQL语句 今天转移数据库数据,需要把数据库原来的表和存储过程清空.删除所有的表:如果由于外键约束删除table失败,则先删除所有约束: --/第1步****** ...

  8. 05_Python格式化打印

    一般框架 tplt = '' #格式化模板 print(tplt.format(…)) #填充内容 tplt = '{0}-{1}+{2}={3}' {}表示了一个槽,槽里面的内容使用key:valu ...

  9. Python进程间通信和网络基础

    Python进程间通信和网络基础 Python支持多种进程间通讯的方式, 有单机通信的signal和mmap等, 也有可以通过网络的socket方式, 这里先介绍select等的有关知识, socke ...

  10. LVM逻辑分区的优缺点与步骤

    一.LVM简介 1. 什么是LVM? LVM是 Logical Volume Manager(逻辑卷管理)的简写 2. 为什么使用LVM? LVM通常用于装备大量磁盘的系统,但它同样适于仅有一.两块硬 ...