package test_one;

import java.lang.*;
import java.io.File;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.testrunner.UiAutomatorTestCase; import android.R.id;
import android.R.string;
import android.os.RemoteException; import com.android.uiautomator.core.UiWatcher;
import com.android.uiautomator.core.UiObjectNotFoundException; @SuppressWarnings("deprecation")
public class Test_ojb extends UiAutomatorTestCase{
public int startapp(String componentName){
StringBuffer app = new StringBuffer();
app.append("am start -n");
app.append(componentName);
int ret = 1;
try{
Process process = Runtime.getRuntime().exec(app.toString());
ret = process.waitFor(); }catch(Exception e){
e.printStackTrace();
System.out.println("startapp Exception!!! "); }
return ret;
} public void test_one_Test()throws UiObjectNotFoundException,RemoteException{
for(int j=0; j<10; j++){
if (UiDevice.getInstance().isScreenOn()) {
System.out.println("screen OK!"); }else{
UiDevice.getInstance().wakeUp();
System.out.println("The screen is lit ! ");
}
UiDevice.getInstance().pressHome();
UiObject Unlocked = new UiObject(new UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller"));
assertTrue("Unlocked NG!",Unlocked.exists());
try {
Unlocked.swipeUp(20);
System.out.println("OK! The desktop unlocked successfully");
} catch (Exception e) {
e.printStackTrace();
System.out.println("NG! Unlock failed!");
}
UiObject launcher1 = new UiObject(new UiSelector().resourceId("com.android.launcher3:id/layout")
.className("android.view.View")
.packageName("com.android.launcher3"));
UiObject launcher2 = launcher1.getChild(new UiSelector().index(0));
UiObject application = launcher2.getChild(new UiSelector().index(2)
.className("android.widget.TextView")
.packageName("com.android.launcher3"));
assertTrue("application NG!",application.exists());
try{
application.clickAndWaitForNewWindow();//点击进入应用
System.out.println("application click ok!");
} catch (UiObjectNotFoundException e){
e.printStackTrace();
System.out.println("NG! Application click failed! ");
UiDevice.getInstance().pressHome();
sleep(2000);
application.clickAndWaitForNewWindow();
}
UiObject View_1 = new UiObject(new UiSelector().resourceId("com.android.launcher3:id/apps_customize_pane_content")
.className("android.view.View"));
UiObject view_2 = View_1.getChild(new UiSelector().className("android.view.View").index(0));
UiObject view_3 = view_2.getChild(new UiSelector().className("android.view.View").index(2));
for(int i=0;i<view_3.getChildCount();i++){ //遍历桌面
try{
UiObject obj = view_3.getChild(new UiSelector().className("android.widget.TextView").index(i));
assertTrue("NG!"+i+"could not find it", obj.exists());
obj.click();
System.out.println(i+"start OK!");
sleep(5000);
UiDevice.getInstance().pressBack();
if(view_3.waitForExists(10000)){
System.out.println("return!");
}else{
UiDevice.getInstance().pressBack();
}
sleep(1000);
}catch (UiObjectNotFoundException e) {
e.printStackTrace();
System.out.println("NO:"+i+"_NG!");
File Screenshot = new File("/mnt/sdcard/"+"log_"+i+".png");
UiDevice.getInstance().takeScreenshot(Screenshot);
UiDevice.getInstance().pressHome();
sleep(2000);
application.clickAndWaitForNewWindow();
}
}
UiDevice.getInstance().pressHome();
sleep(1000);
UiDevice.getInstance().sleep();
}
}
}

												

最新文章

  1. C#-WebForm-文件上传-FileUpload控件
  2. char_dev.c 添加中文注释
  3. python 识别图片验证码报IOError
  4. stopPropagation, preventDefault 和 return false
  5. Lintcode: Route Between Two Nodes in Graph
  6. centos7重置root开机登录密码
  7. 一个简单的CS系统打包过程图文版
  8. MySQL --slave-skip-errors
  9. 修改android应用包名 分类: android 学习笔记 2015-07-16 22:48 4人阅读 评论(0) 收藏
  10. CSS3 div水平、垂直居中,IE9以上、Firefox、Chrome均正常
  11. 修改Linux命令提示符
  12. CORS跨域 Ajax headers 问题
  13. LOJ #6285 分块入门9
  14. 第十四届智能车培训 PLL锁相环
  15. continue #结束本次循环进行下次循环
  16. select监听udp消息
  17. SQL求出优秀、及格人数
  18. 大数据系列博客之 --- 深入简出 Shell 脚本语言(基础篇)
  19. localstorage检测
  20. 2017年Android百大框架排行榜

热门文章

  1. [转载] C# DllImport用法和路径问题
  2. Spring Cloud(Dalston.SR5)--Eureka 常用配置
  3. kindle电子书下载搜索
  4. nginx支持android、ios、微信扫一扫
  5. 黄聪:php7配置php.ini使其支持&lt;? ?&gt;
  6. windows 下跟踪日志的几个工具总结
  7. HTTP之Cookie
  8. C#多线程更新,查询MongoDB数据
  9. [转]jvm加载类规则
  10. Hive数据类型及文本文件数据编码