uiautomator 代码记录 : 随机发送短信
package sms_test;
import java.lang.*;
import java.util.Random;
import javax.microedition.khronos.egl.EGL10;
import java.io.File;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import android.R.plurals;
import android.os.RemoteException;
import com.android.uiautomator.core.UiCollection;
import com.android.uiautomator.core.UiObjectNotFoundException;
public class SMS_Test extends UiAutomatorTestCase {
String startsms = "com.android.mms/com.android.mms.ui.ConversationList";
public void startapp (String ojb){
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_SMS_Test() throws UiObjectNotFoundException,RemoteException{
String a = "abcdefg";
String b = "1234567";
String c = "aaabbccddeeffgg112233445566778899";
String d = "#@+=-)(4451318fdggd";
String e = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddd"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd";
String a1 = "10086";
String a2 = "10086101";
String a3 = "10010";
String SMS_content[] = {a,b,c,d,e};
String Send_the_number[] ={a1,a2,a3};
try{
for(int i=0; i<10 ;i++){
sleep(1000);
UiDevice.getInstance().sleep();
if(UiDevice.getInstance().isScreenOn()){
System.out.println("The screen is on!");
}else{
UiDevice.getInstance().wakeUp();
sleep(1000);
}
UiObject Unlocked = new UiObject(new UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller"));
assertTrue("Unlocked Exception!", Unlocked.exists());
Unlocked.swipeUp(20);
sleep(1000);
startapp(startsms);//启动短信
System.out.println("start apk....");
UiObject sms_1 = new UiObject(new UiSelector().resourceId("android:id/list"));
sms_1.waitForExists(5000);
assertTrue("sms_1 Exception!", sms_1.exists());
UiObject new_SMS = new UiObject(new UiSelector().resourceId("com.android.mms:id/action_compose_new").description("新信息"));
assertTrue("new_SMS Exception!",new_SMS.exists());
new_SMS.clickAndWaitForNewWindow();
UiObject Enter_the_number = new UiObject(new UiSelector().text("输入名字或号码")
.resourceId("com.android.mms:id/recipients_editor"));
assertTrue("Enter_the_number Exception!", Enter_the_number.exists());
Enter_the_number.click();
sleep(2000);
Random r = new Random();
int e1=r.nextInt(3);
Enter_the_number.setText(Send_the_number[e1]); //输入发送号码
UiObject Enter_the_content = new UiObject(new UiSelector().text("输入文本信息")
.resourceId("com.android.mms:id/embedded_text_editor"));
assertTrue("Enter_the_content Exception!",Enter_the_content.exists());
sleep(5000);
Enter_the_content.click();
sleep(2000);
Random k = new Random();
Enter_the_content.setText(SMS_content[k.nextInt(5)]); //输入信息内容
sleep(5000);
UiObject send = new UiObject(new UiSelector().resourceId("com.android.mms:id/send_button_sms"));
assertTrue("send Exception!", send.exists());
send.clickAndWaitForNewWindow();
UiObject CMCC = new UiObject(new UiSelector().text("中国移动")
.resourceId("android:id/title"));
UiObject CUCC = new UiObject(new UiSelector().text("中国联通").resourceId("android:id/title"));
assertTrue("CMCC Exception!...",CMCC.exists());
assertTrue("CUCC Exception!...",CUCC.exists());
if(a1.equals(Send_the_number[e1])){ //判断输入的号码是联通号码还是移动号码
CMCC.clickAndWaitForNewWindow();
System.out.println("CMCC send...");
}else if(a2.equals(Send_the_number[e1])){
CMCC.clickAndWaitForNewWindow();
System.out.println("CMCC send...");
}else if(a3.equals(Send_the_number[e1])){
CUCC.clickAndWaitForNewWindow();
System.out.println("CUCC send...");
}
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiObject Letter = new UiObject(new UiSelector().resourceId("com.android.mms:id/mark_as_read_btn").text("关闭"));
boolean boolean_letter = Letter.waitForExists(30000);
if(boolean_letter){
Letter.clickAndWaitForNewWindow();
}
else {
UiDevice.getInstance().pressBack();
}
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
}catch(UiObjectNotFoundException e5){
e5.printStackTrace();
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
UiDevice.getInstance().pressBack();
sleep(1000);
}
}
}
uiautomator 代码记录 : 随机发送短信的更多相关文章
- 超实用的JavaScript代码段 Item4 --发送短信验证码
发送短信验证码 实现点击“发送验证码”按钮后,按钮依次显示为“59秒后重试”.“58秒后重试”…直至倒计时至0秒时再恢复显示为“发送验证码”.在倒计时期间按钮为禁用状态 . 第一步.获取按钮.绑定事件 ...
- java发送短信--httpclient方式
最近头让我写个发送短信的java程序检测BI系统,检查数据库是否有异常发送,有则发送短信到头的手机里.这里我直说httpclient方式的get请求方式,并且已经有方式的短信的接口了,所以只要再加上参 ...
- Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘
apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...
- Android发送短信核心代码
核心代码:(1)SmsManager manager = SmsManager.getDefault(); //获得默认的消息管理器(2)ArrayList<String> list = ...
- 使用短信猫发送短信java代码
短信猫简单配置:https://www.cnblogs.com/Big-Boss/p/9699880.html 发送短信: package utils; import org.smslib.AGate ...
- js 发送短信倒计时、秒杀倒计时实现代码
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- js 忘记密码发送短信记录cookie
<div class="forgetPwdBox" style="display:none"> <div class="forTit ...
- WPF MVVM下做发送短信小按钮
最近做一个项目,因为涉及到注册,因此需要发送短信,一般发送短信都有一个倒计时的小按钮,因此,就做了一个,在此做个记录. 一.发送消息 没有调用公司的短信平台,只是模拟前台生成一串数字,将此串数字输出一 ...
- a标签的妙用-拨打电话、发送短信、发送邮件
前端时间在做手机WAP网站时,遇到需要点击页面上显示的电话号能直接拨号的需求,查找资料发现可以使用html的a标签完美实现该需求!记录下来以备后用...... 目前主流手机浏览器对H5的支持已经很不错 ...
随机推荐
- Zookeeper 配置集群环境详解
在Linux环境下安装zookeeper 在Linux环境下安装zookeeper 1. 将zookeeper-3.4.13.tar.gz复制到linux操作系统 2. 通过p ...
- 关于bool 与boolean
关于bool的介绍,整理如下: bool 关键字是 System.Boolean 的别名.它用于声明变量来存储布尔值 true 和 false. 如果需要一个也可以有 null 值的布尔型变量,请使用 ...
- TStrings与Memo.Lines赋值的问题
//想实现在函数中生成Memo1的内容,而后赋给Memo.Lines //方法1: var s: TStrings; begin s := TStringList.Create; AddMemoDat ...
- [NEWS]Microsoft expands partnerships with AOL and AppNexus, Bing to power search for AOL properties
http://advertising.microsoft.com/en/blog/33906/microsoft-expands-partnerships-with-aol-and-appnexus- ...
- NP完全性理论与近似算法
转自:http://www.cnblogs.com/chinazhangjie/archive/2010/12/06/1898070.html 一.图灵机 根据有限状态控制器的当前状态及每个读写头读到 ...
- 《剑指offer(第二版)》——面试题36:二叉搜索树与双向链表
具体的题目大意和参考思路在此处不详述(见<剑指offer>),实质就是在中序遍历的过程中调整指针的指向,关于中序遍历有递归和非递归两种操作,所以此处也用了两种方法. 方法1(递归法): 代 ...
- vagrant在windows下的安装和配置
记录一下安装和配置过程中的一些坑步骤一分别下载vagrant和VirtualBox,我这里下载的是vagrant_1.9.1.msi 和 VirtualBox-5.1.14-112924-Win.ex ...
- Android兼容包之MultiDex
一.MultiDex的产生背景 当Android系统安装一个应用的时候,有一步是对Dex进行优化,这个过程有一个专门的工具来处理,叫DexOpt.DexOpt的执行过程是在第一次加载Dex文件的时候执 ...
- python 引用计数
转载:NeilLee(有修改) 一.概述 要保持追踪内存中的对象,Python使用了引用计数这一简单的技术. sys.getrefcount(a)可以查看a对象的引用计数,但是比正常计数大1,因为 ...
- react事件中的事件对象和常见事件
不管是在原生的js还是vue中,所有的事件都有其事件对象,该事件对象event中包含着所有与事件相关的信息,在react中,所有的事件也有其事件对象,在触发DOM上的某个事件时,就会产生一个事件对象. ...