UiAutomator 代码记录: 随机创建新联系人
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 代码记录: 随机创建新联系人的更多相关文章
- EBS管理员为供应商创建新联系人流程
管理员为供应商创建新联系人流程 /oracle/apps/pos/supplier/webui/ByrAddCntctPG oracle.apps.pos.supplier.webui.ByrAddC ...
- uiautomator 代码记录 : 随机发送短信
package sms_test; import java.lang.*; import java.util.Random; import javax.microedition.khronos.egl ...
- 【OpenGL】代码记录01创建窗口
创建空窗口: #include<iostream> // GLEW #define GLEW_STATIC #include <GL/glew.h> // GLFW #incl ...
- uiautomator 代码记录 :BT接收测试
package rom; import java.lang.*; import java.util.Random; import java.io.File; import com.android.ui ...
- uiautomator 代码记录 : BT发送测试
package rom; import java.lang.*; import java.util.Random; import java.io.File; import com.android.ui ...
- UiAutomator 代码记录 : 遍历桌面
package test_one; import java.lang.*; import java.io.File; import com.android.uiautomator.core.UiDev ...
- Ubuntu创建新用户的正确姿势
作者按:因为教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步<Ubuntu 创建新用户的正确姿势>原文地址.更欢迎来我的小站看更多原创内容:godbmw.com,进行&q ...
- git 创建新项目,下载工程,合并和更新工程简单应用记录
以前使用SVN很顺手,现在公司使用git来管理代码,因此学习git的基本使用. 一.首先介绍下SVN和git的简单比较: SVN是使用得最多的版本控制管理工具. 1.是一个集中式的版本管理工具.所有的 ...
- 【neo4j】文件管理路径、数据备份、创建新数据库、导入数据等操作记录
neo4j一般的配置路径如下 一.备份数据 使用neo4j-admin命令. 首先,先找到数据的存储路径,然后关闭数据库. 关闭数据库的语句如下: #切换到/bin目录下 ./neo4j stop 然 ...
随机推荐
- linux系统中安装JDK 查看安装的ava版本
一.安装JDK 1.在/usr/目录下创建java目录 [root@localhost ~]# mkdir/usr/java[root@localhost ~]# cd /usr/java 2.下载j ...
- RedHat6.5创建本地yum源
拷贝Linux操作系统的rhel-server-6.5-x86_64-dvd.iso镜像到装好的Linux中: #执行挂载命令 mount –o loop /media/rhel-server-6.5 ...
- linux环境下python的pdb调试方法
一些常用指令: h(elp) [comman] #打印可用指令及帮助信息 r(eturn) #运行代码直到下一个断点或当前函数返回 b(reak) [[filename:]lineno | fun ...
- Delphi:窗体的扩展样式GWL_EXSTYLE用于SetWindowLong
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_ ...
- influxDB 0.9 C# 读写类
influxDB 0.9 C# 读写类 目前influxdb官网推荐的C#读写类是针对0.8版本的,截至本文写作之前,尚未发现有针对0.9的读写类. 我使用influxdb的是用于保存服务器的运行 ...
- Mysql 性能优化6【重要】 索引优化
b tree索引 myisam 是通过物理位置来查找引用行的 innodb 是通过主键来查找引用行的 索引优化策略 b-tree索引对数据长度有限制,所以text等比较长的列可以建立前缀索引 btre ...
- win10和ubuntu16.04双系统时间同步
在win10安装了ubuntu双系统,发现在两个系统见时间相差8个小时,这是由于windows和和ubuntu对于从主板取得时间后的处理方式不同,如果你把位置设为上海,ubuntu总是把主板时间当作u ...
- PREV-5_蓝桥杯_错误票据
问题描述 某涉密单位下发了某种票据,并要在年终全部收回. 每张票据有唯一的ID号.全年所有票据的ID号是连续的,但ID的开始数码是随机选定的. 因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成 ...
- http系列(一)
一.关于Url URI由URL和URN组成,URI即统一资源标识符,URL即统一资源定位符,URN即统一资源名称. 现在最常用的是URL. 二.http请求/响应报文 请求报文:请求行.请求头部.空行 ...
- 写在vue总结之前(二)
都说要快速学会一个技术(会使用),比如一个框架,在实际的工作中做相关的项目是最快的学习方式.而为什么在实际的工作项目中去学习是最快的方式?个人的体会是,在实际的工作项目中,很多功能的实现是你不得不做的 ...