观心静

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  422 随笔 :: 0 文章 :: 86 评论 :: 139万 阅读
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);
			
		}
	}
}

posted on   观心静  阅读(258)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示