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 然 ...
随机推荐
- VS未能正确加载包
这个方法同样适用于多个版本的VS 首先关闭VS进这里:C:\Users\用户名\AppData\Roaming\Microsoft\VisualStudio\11.0(2012是11.0,根据你的VS ...
- 修改postfix smtp端口,防止公网扫描浪费你的服务器流量
邮件服务器的默认发送邮件端口是25,一些ISP会封锁25端口防止垃圾邮件的发送,这样就导致不能使用Foxmail.outlook等邮件客户端发送邮件.修改默认smtp端口就可以解决这个问题.下面的方法 ...
- ML: 聚类算法R包-K中心点聚类
K-medodis与K-means比较相似,但是K-medoids和K-means是有区别的,不一样的地方在于中心点的选取,在K-means中,我们将中心点取为当前cluster中所有数据点的平均值, ...
- gtid error set test
1.从库报主键重复(Errno: 1062)#create test data 1062create table t1 (id tinyint not null primary key,ename v ...
- centos 磁盘清理 /dev/vda1系统盘满了
df -h 检查一台服务器磁盘使用空间,发现磁盘已经使用了100% 思路是: 1.cd /usr 当然这里不一定是/usr目录,最好是cd到 根目录再执行下一步 2.du -sh * 看哪 ...
- 两种方式:mysql查看正在执行的sql语句
mysql查看正在执行的sql语句 2015年08月21日 17:32:59 阅读数:15398 有2个方法: 1.使用processlist,但是有个弊端,就是只能查看正在执行的sql语句,对应 ...
- RTB业务知识之2-Impression概念和关键属性
一.定义-impression This object describes an ad placement or impression being auctioned. A single bid re ...
- ASP.NET重写Render 加载CSS样式文件和JS文件(切换CSS换皮肤)
网页换皮肤的方式有很多种,最简单的通常就是切换页面CSS,而CSS通常写在外部CSS文件里.那么切换CSS其实就是更换html里的link href路径.我在网上搜索了下. 一般有两种方式: 1.页面 ...
- JS之滚动条效果2
在前面一篇说的是滚动条效果,本篇继续在前面的基础上面针对滚动条进行操作.本次要实现的效果如下:拖动滚动条左右移动时,上面的图片内容也相对外层盒子做相对移动. 下面针对要实现的效果进行分析:首先是页面基 ...
- Scala集合类型详解
Scala集合 Scala提供了一套很好的集合实现,提供了一些集合类型的抽象. Scala 集合分为可变的和不可变的集合. 可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合 ...