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 然 ...
随机推荐
- sparkSQL以JDBC为数据源
一.环境准备 安装oracle后,创建测试表.数据: create table test ( username varchar2(32) primary key , password varchar2 ...
- phpmailer使用qq邮箱、163邮箱成功发送邮件实例代码
以前使用qq邮箱.163服务器发送邮件,帐号直接使用密码,现在不行了,得使用授权码,简单记录下 1.首先开通POP3/SMTP服务,qq邮箱——帐号——设置,找到POP3/SMTP点开启,输入短信会有 ...
- gtid error set test
1.从库报主键重复(Errno: 1062)#create test data 1062create table t1 (id tinyint not null primary key,ename v ...
- 运动目标检测中基于HSV空间的阴影去除算法
在运动目标检测中,常常会出现由于光线被遮挡,或场景其他物体的遮挡,在目标附近或场景里出现阴影,阴影的出现对后期目标的正确分割与处理带了很大的不便.如今,国内外已有不少文献来研究这个问题,并且提出了各种 ...
- Docker的一些概念
Docker的一些概念 2.1 什么是Docker? 说实话关于Docker是什么并太好说,下面我通过四点向你说明Docker到底是个什么东西. Docker 是世界领先的软件容器平台. Docker ...
- Zuul Read Time out 错误
只改application.yml文件即可: eureka: client: serviceUrl: defaultZone: http://localhost:7087/eureka/ server ...
- pandas.DataFrame 插入列和行
转载:www.360doc.com/content/17/0225/23/1489589_632032302.shtml 以csv实例文件操作插入DataFrame的行和列 文件名:example.c ...
- win server 2003 x64 IIS配置
新装IIS第一个报错 The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine 原因是 服务器 IIS ...
- java1.8新特性(一)
一直在更新java 版本,原来也没有关注java版本的变化 引入的一些新的api 引起注意的还是 关于一些并发包的使用,那时候才对每个版本的特性 去了解了一下,虽然 不一定都用上了,但是不管学习什 ...
- Java学习---异常处理
import java.util.Scanner; public class MyExceptionTest { public static void check(Square A) throws W ...