package lecturer;

import java.lang.*;
import java.nio.Buffer;
import java.util.Random;
import java.io.File;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import android.R.string;
import android.os.RemoteException;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiObjectNotFoundException; public class Lecturer extends UiAutomatorTestCase {
public String Random_text(){ //生成随机手机字符串方法
String a[] = {"a","b","c","d","e","f","g","h","w","j","k","l","n","m","o","p","q","r","s","t","u","v","w","x","Y","z"};
String A[] = {"A","B","C","D","E","F","G","H","W","J","K","L","N","M","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String symbol[] = {"!","@","#","$","%","^","&","*","(",")","+","=","-",";","'","?","~","|","[","]","{","}","`"};
String digital[] = {"1","2","3","4","5","6","7","8","9","0"};
String set[][] = {a,A,symbol,digital};
Random length = new Random();
StringBuffer buffer = new StringBuffer();
int length_a = length.nextInt(21)+1;
for(int i=0;i<length_a;i++){
Random random = new Random();
Random random2 = new Random();
int select = random.nextInt(4);
if (set[select].equals(a)){
buffer.append(set[select][random2.nextInt(26)]);
}
else if(set[select].equals(A)){
buffer.append(set[select][random2.nextInt(26)]);
}
else if(set[select].equals(symbol)){
buffer.append(set[select][random2.nextInt(23)]);
}
else if(set[select].equals(digital)){
buffer.append(set[select][random2.nextInt(10)]);
}
}
return buffer.toString();
}
public String Random_Value(){ //生成随机数值的方法
String Value[] = {"1","2","3","4","5","6","7","8","9","0"};
StringBuffer Value_buffe =new StringBuffer();
for(int j=0; j<12;j++){
Random Value_Random = new Random();
Value_buffe.append(Value[Value_Random.nextInt(10)]);
}
return Value_buffe.toString();
}
public void Screenshot(String name) { //截取当前屏幕图片的方法
File file = new File("/mnt/sdcard/log"+name+".png");
UiDevice.getInstance().takeScreenshot(file);
}
public void startapp(String ojb){ //启动apk的方法
StringBuffer app = new StringBuffer();
app.append("am start -n");
app.append(ojb);
try{
Process process = Runtime.getRuntime().exec(app.toString());
process.waitFor();
}
catch (Exception e) {
e.printStackTrace();
System.out.println("NG! Start apk failed....");
}
}
public void test_lecturer()throws UiObjectNotFoundException,RemoteException {
for(int k=0;k<20;k++){
try{
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().sleep();
sleep(2000);
UiDevice.getInstance().wakeUp();
}catch(RemoteException e1) {
e1.printStackTrace();
System.out.println("NO:"+k+"....wakeup Exception!.... ");
sleep(2000);
UiDevice.getInstance().sleep();
sleep(2000);
UiDevice.getInstance().wakeUp();
}
try{
UiObject Unlock = new UiObject(new UiSelector().resourceId("com.android.systemui:id/preview_container")
.className("android.widget.FrameLayout"));
assertTrue("Unlock fail!...", Unlock.exists());
Unlock.swipeUp(20);//滑屏解锁
sleep(1000);
}catch(UiObjectNotFoundException e2){
e2.printStackTrace();
System.out.println("NO:"+k+"....Unlock Exception!.... ");
Screenshot("Unlock_Exception"+k);
sleep(2000);
UiDevice.getInstance().sleep();
sleep(2000);
UiDevice.getInstance().wakeUp();
sleep(2000);
UiObject Unlock = new UiObject(new UiSelector().resourceId("com.android.systemui:id/preview_container")
.className("android.widget.FrameLayout"));
assertTrue("Unlock fail!...", Unlock.exists());
Unlock.swipeUp(20);//滑屏解锁
}
startapp("com.android.contacts/com.android.contacts.activities.PeopleActivity");//启动联系人
sleep(2000);
try{
UiObject new_contact = new UiObject(new UiSelector().resourceId("com.android.contacts:id/floating_action_button")
.description("添加新联系人"));
assertTrue("new_contact fail!...",new_contact.exists());
new_contact.clickAndWaitForNewWindow();
}catch (UiObjectNotFoundException e3) {
e3.printStackTrace();
System.out.println("NO:"+k+"....new_contact Exception!.... ");
Screenshot("new_contact"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
try{
UiObject Name = new UiObject(new UiSelector().text("姓名").className("android.widget.EditText"));
assertTrue("Name fail!...", Name.exists());
Name.click();
Name.setText(Random_text());
sleep(1000);
}catch (UiObjectNotFoundException e4) {
e4.printStackTrace();
System.out.println("NO:"+k+"....Enter_the_contact_name Exception!.... ");
Screenshot("Enter_the_contact_name"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
try{
UiObject Pinyin_of_name = new UiObject(new UiSelector().text("姓名拼音").className("android.widget.EditText"));
assertTrue("Pinyin_of_name fail!...",Pinyin_of_name.exists());
Pinyin_of_name.click();
Pinyin_of_name.setText(Random_text());
sleep(1000);
}catch (UiObjectNotFoundException e5) {
e5.printStackTrace();
System.out.println("NO:"+k+"....Enter the name Pinyin Exception!.... ");
Screenshot("Pinyin_of_name"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
try{
UiObject nickname = new UiObject(new UiSelector().text("昵称").className("android.widget.EditText"));
assertTrue("nickname fail!...",nickname.exists());
nickname.click();
nickname.setText(Random_text());
sleep(1000);
}catch (UiObjectNotFoundException e6) {
e6.printStackTrace();
System.out.println("NO:"+k+"....Enter the nickname Exception!.... ");
Screenshot("nickname"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
try{
UiScrollable Scroll_contact = new UiScrollable(new UiSelector().resourceId("com.android.contacts:id/contact_editor_fragment")
.className("android.widget.ScrollView")); //定位滚动元素
assertTrue("Scroll_contact fail!...",Scroll_contact.exists());
UiObject number = new UiObject(new UiSelector().text("电话").className("android.widget.EditText"));
Scroll_contact.scrollIntoView(number);
sleep(1000);
number.click();
number.setText(Random_Value());
sleep(1000);
}catch(UiObjectNotFoundException e7){
e7.printStackTrace();
System.out.println("NO:"+k+"....Scroll and enter the number Exception!.... ");
Screenshot("number"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
try{
UiObject determine = new UiObject(new UiSelector().resourceId("com.android.contacts:id/menu_done")
.className("android.widget.TextView"));
assertTrue("determine fail! ...",determine.exists());
determine.clickAndWaitForNewWindow();
}catch (UiObjectNotFoundException e8) {
e8.printStackTrace();
System.out.println("NO:"+k+"....determine Exception!.... ");
Screenshot("determine"+k);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
sleep(1000);
Screenshot("Screenshot_contacts"+k);
sleep(2000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
} }

UiAutomator 代码记录: 随机创建新联系人的更多相关文章

  1. EBS管理员为供应商创建新联系人流程

    管理员为供应商创建新联系人流程 /oracle/apps/pos/supplier/webui/ByrAddCntctPG oracle.apps.pos.supplier.webui.ByrAddC ...

  2. uiautomator 代码记录 : 随机发送短信

    package sms_test; import java.lang.*; import java.util.Random; import javax.microedition.khronos.egl ...

  3. 【OpenGL】代码记录01创建窗口

    创建空窗口: #include<iostream> // GLEW #define GLEW_STATIC #include <GL/glew.h> // GLFW #incl ...

  4. uiautomator 代码记录 :BT接收测试

    package rom; import java.lang.*; import java.util.Random; import java.io.File; import com.android.ui ...

  5. uiautomator 代码记录 : BT发送测试

    package rom; import java.lang.*; import java.util.Random; import java.io.File; import com.android.ui ...

  6. UiAutomator 代码记录 : 遍历桌面

    package test_one; import java.lang.*; import java.io.File; import com.android.uiautomator.core.UiDev ...

  7. Ubuntu创建新用户的正确姿势

    作者按:因为教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步<Ubuntu 创建新用户的正确姿势>原文地址.更欢迎来我的小站看更多原创内容:godbmw.com,进行&q ...

  8. git 创建新项目,下载工程,合并和更新工程简单应用记录

    以前使用SVN很顺手,现在公司使用git来管理代码,因此学习git的基本使用. 一.首先介绍下SVN和git的简单比较: SVN是使用得最多的版本控制管理工具. 1.是一个集中式的版本管理工具.所有的 ...

  9. 【neo4j】文件管理路径、数据备份、创建新数据库、导入数据等操作记录

    neo4j一般的配置路径如下 一.备份数据 使用neo4j-admin命令. 首先,先找到数据的存储路径,然后关闭数据库. 关闭数据库的语句如下: #切换到/bin目录下 ./neo4j stop 然 ...

随机推荐

  1. DevOps需要的工具

    DevOps需要的工具: 代码管理(SCM):GitHub.GitLab.BitBucket.SubVersion 构建工具:Ant.Gradle.maven 自动部署:Capistrano.Code ...

  2. 线程【五】VCL下的线程类

    在这里把网友常常搞不清楚的属性作用列出来: 一.FreeOnTerminate用于表明线程执行完毕后是自动释放还是保留,默认为False 二.Terminate 该过程只是简单地设置线程类的Termi ...

  3. linux 添加多个网段

    1.在系统中添加网络配置文件脚本 # cd /etc/sysconfig/network-scripts # cp ifcfg-eth0 ifcfg-eth0:0 2.修改新添加的网络配置脚本文件如下 ...

  4. 简单谈谈JS数组中的indexOf方法

    前言 相信说到 indexOf 大家并不陌生,判断字符串是否包涵子字符串时特别常用,正则不熟练同学的利器.这篇文章就最近遇到的一个问题,用实例再说说说indexOf方法.本文是小知识点积累,不作为深入 ...

  5. 并查集(Union-Find)

    常见问题: 首先在地图上给你若干个城镇,这些城镇都可以看作点,然后告诉你哪些对城镇之间是有道路直接相连的.最后要解决的是整幅图的连通性问题.比如随意给你两个点,让你判断它们是否连通,或者问你整幅图一共 ...

  6. 黄聪:PHP调试显示所有错误信息

    ini_set('display_errors',1); //错误信息 ini_set('display_startup_errors',1); //php启动错误信息 error_reporting ...

  7. Java第06次实验提纲(集合)

    PTA与参考资料 重要参考-集合简述 题集:jmu-Java-06-集合 集合实验文件 第1次实验 1.1 ArrayListIntegerStack(课堂演示) 可演示:jdk中的javadoc文档 ...

  8. spring AOP的学习

    1.Spring常用的概念 Joinpoint(连接点): 所谓连接点是指那些被拦截到的点.在spring中,这些点指的是方法,因为spring只支持方法类型的连接点. Pointcut(切入点): ...

  9. 寻找数组中第K大的数

    给定一个数组A,要求找到数组A中第K大的数字.对于这个问题,解决方案有不少,此处我只给出三种: 方法1: 对数组A进行排序,然后遍历一遍就可以找到第K大的数字.该方法的时间复杂度为O(N*logN) ...

  10. Ubuntu 14.10 下ZooKeeper+Hadoop2.6.0+HBase1.0.0 的HA机群高可用配置

    1 硬件环境 Ubuntu 14.10 64位 2 软件环境 openjdk-7-jdk hadoop 2.6.0 zookeeper-3.4.6 hbase-1.0.0 3 机群规划 3.1 zoo ...