VoLTE和语音呼通率测试开发--被叫终端(一)

219 阅读3分钟

现在我们要测试两台终端的接通率,这里我只写VoLTE视频通话的呼叫,一般使用移动卡,且开通VOLTE业务。视频通话功能!

我们基于uiautomatior框架。在uiautomatior中有来电监听API的UIwatchar,不懂得百度;一般在在自动化的时候,监听是为了测试过程会有来电中断测试,所以监听一有来电就挂掉,不让它影响测试;

我们这里监听不是为了挂断,是为了接听,思路很简单:当有来电(VoLTE视频通话)来电,就接听等场景就行。

 

开发需求:volte 通话次数50 次、通话时长180s、间隔时间30s、呼叫超时时间30s

 

VoLTE视频通话:

代码如下:匆匆忙忙写的,格式很乱,被注释的语句请忽略(或者删除),只看中文注释

package uiauto;


//import util.Bundle;
//import util.RemoteException;
//import util.UiObjectNotFoundException;
import util.Common;
import util.PackageEvent;
import util.CmdAdb;
import util.ImgCompare;
import util.Location;
import util.Selector;
import util.FileUtil;
import java.io.BufferedWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;



import android.os.Bundle;
import android.os.RemoteException;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.core.UiWatcher;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class Answerphone extends UiAutomatorTestCase {
//	Common common = new Common();
//	PackageEvent packageEvent = new PackageEvent();
	private static final long TIME_OUT = 10 * 60 * 1000;  
    private long currentTime;  
    private boolean flag = true;  
  
    long eslcape = 0; 
    
	public void testAnswerphone() throws Exception{//Exception
	int count=1;
	int count1=1;

	UiObject JietingOne = new UiObject(new UiSelector().text("视频通话来电"));//��Ƶͨ������视频通话来电
//	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/videoCallIcon"));//��Ƶͨ������VOLET来电小图标

//1/	
	/*UiWatcher inComingWatcher = new MyWatcher();  
    getUiDevice().registerWatcher("来电", inComingWatcher);  
     
    getUiDevice().pressBack();  
//    UiObject dialButton = new UiObject(new UiSelector().resourceId("com.android.sprdlauncher1:id/workspace"));  
    System.out.println("waiting for incoming");  
    currentTime = System.currentTimeMillis();  
    while (flag && eslcape < TIME_OUT) {  
//    	VOLTEcall.clickAndWaitForNewWindow();  
    	Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
        eslcape = System.currentTimeMillis() - currentTime;  
    }  
    assertFalse("没有收到来电", flag);  
}  


class MyWatcher implements UiWatcher {  

//    @Override  
    public boolean checkForCondition() {  
//        UiObject inCall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/IncomingCallRejectButton"));  
    	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
        while (eslcape < TIME_OUT) {  
            if (VOLTEcall.exists()) {  
                System.out.println("you have a call");  
                try {  
//                	VOLTEcall.clickAndWaitForNewWindow();  
                	System.out.println("22222222222");  
                	Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
                    flag = false;  
                    return true;  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
            eslcape = System.currentTimeMillis() - currentTime;  
        }  
        return false;  
    }  */
//1	

	
//2///
	//监听
	System.out.println("Log:00000000");
	for(int j = 1; j > 0; j++){//j = 0; j < 40; j++
		System.out.println("Log:aaaaaaaa");
	    UiDevice.getInstance().registerWatcher("phone", new UiWatcher() {
	    UiObject JietingOne = new UiObject(new UiSelector().text("视频通话来电"));//��Ƶͨ������视频通话来电
		UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/videoCallIcon"));//��Ƶͨ������VOLET来电小图标
		  public boolean checkForCondition() {
				System.out.println("Log:VOLTEcall wait");
				if(!VOLTEcall.exists()){
					try {
						System.out.println("Log:bbbbbbbbbbbb");
						Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
//						VOLTEcall.swipeRight(20);//接听
//						return true;
					} catch (Exception e) {
						// TODO: handle exception
					}
				  System.out.println("Log:VOLTEcall false");
	              return true;
				}
				System.out.println("Log:VOLTEcall success");
				return false;
			}
		});
	
		System.out.println("Log:1111111");
		sleep(10000);
	  if(!VOLTEcall.exists()){
		 System.out.println("Log:2222222");
		 sleep(1000);
//		 if(getUiDevice().isScreenOn()){//熄屏
//				getUiDevice().sleep();
//			}
//		 Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
//		 VOLTEcall.swipeRight(20);//接听	
	  }else{
		 System.out.println("Log:3333333"); 
//		 getUiDevice().sleep();//息屏
	   }
	}
}
	/*//监听来电
	UiDevice.getInstance().registerWatcher("phone", new UiWatcher() {
	 UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
	  public boolean checkForCondition() {
			// TODO Auto-generated method stub
			System.out.println("VOLTEcall laidian");
			if(VOLTEcall.exists()){
				try {
//					Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
					VOLTEcall.swipeRight(20);//接听
//					return true;
				} catch (Exception e) {
					// TODO: handle exception
				}
			  System.out.println("VOLTEcall success");
              return true;
			}
			System.out.println("VOLTEcall false");
			return false;
		}
	});*/
//2/	
	
	
	
	/*//�ж�来电判断
	Runtime.getRuntime().exec("mkdir sdcard/GotaTestPresure");
	Runtime.getRuntime().exec("mkdir sdcard/GotaTestPresure/CallRecording");
	if(JietingTwo.exists()){//JietingOne.getText().equals("视频通话来电")
//		sleep(20000);//休眠20秒接听
		Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
		FileUtil.out("sdcard/CallRecording/VOLT接听成功.txt", "VOLTE接听成功次数"+count);
		count=count+1;
	}else{
		sleep(20000);//休眠20秒接听
		FileUtil.out("sdcard/GotaTestPresure/CallRecording/VOLTE接听失败.txt", "VOLTE接听失败次数"+count1);
		count1=count1+1;
	}*/

    
/*
	}
	
	
	//ImgCompare imgCompare = new ImgCompare();
	
//	@Override  
    protected void setUp() throws Exception {
		common.creatFile(getClass().getName());
		common.watcherTheError(getUiDevice(), getClass().getName());//运行错误报告监听器
    }  
//    @Override  
    protected void tearDown() throws Exception {  
          
    }  
	public void testDemo() throws UiObjectNotFoundException, RemoteException{
		try{
			callTwo();
		}catch(Exception e){
			common.takeshot(getUiDevice(), getClass().getName());
			e.printStackTrace();
			}
		finally{
			//getUiDevice().pressHome();
		}
	}
	public void callTwo() throws Exception {
		// 红牛系列
		Bundle bundle = getParams();
		String runcount = bundle.getString("runcount");
		System.out.println("被测试的设备名称是" + getUiDevice().getProductName());
		if (getUiDevice().getProductName().contains("e700")) {
			System.out.println("当前被测试的设备被判断为原生Android手机,执行图像对比判断");
			imgCompare();
		} else {
			// nubia系列
			// 如果20秒内没有看到来电界面,则算作失败
			for (int j = 0; j < 40; j++) {
				String CurrentPackageName =  getUiDevice().getCurrentPackageName();
				if (j == 39) {
					if(!getUiDevice().isScreenOn()){//截图前避免熄屏
						getUiDevice().wakeUp();
					}
					common.takeshotByDate(getUiDevice(), getClass().getName(),"The_"+runcount+"_time_call_fail_");
					System.out.println("第"+runcount+"次未接到来电-" + common.getDate());
				}
				if (CurrentPackageName.contains("incall")||CurrentPackageName.contains("phone")) {// 20秒内来电成功
					if(!getUiDevice().isScreenOn()){//截图前避免熄屏
						getUiDevice().wakeUp();
					}
					common.takeshotByDate(getUiDevice(), getClass().getName(),
							"The_"+runcount+"_time_call_success_");
					System.out.println("第"+runcount+"次接到来电");
					j = 41;
				} else {
					sleep(500);
				}
			}
			sleep(1000);
		}
	}
	
	 * 图片对比
	 
	public void imgCompare() throws RemoteException, UiObjectNotFoundException, FileNotFoundException{
		Bundle bundle = getParams();
		String runcount = bundle.getString("runcount");
		sleep(20000);//等待呼叫的时间20秒,由于红牛来电界面不规范只能通过截图对比
		String picName = "The_"+runcount+"_time_call_Rate_"+common.getDate();
		common.takeshot(getUiDevice(), getClass().getName(), picName);
		sleep(500);
		if (ImgCompare
			.sameAs("/storage/sdcard0/uiauto/CallBefore/Incall.png",
					"/storage/sdcard0/uiauto/CallTwo/" + picName
							+ ".png", 0.95)||ImgCompare
							.sameAs("/storage/sdcard0/uiauto/CallBefore/Incallblack.png",
									"/storage/sdcard0/uiauto/CallTwo/" + picName
											+ ".png", 0.99)) {//桌面截图和黑屏截图两次对比确认未收到来电
			System.out.println("第"+runcount+"次未接到来电-"+common.getDate());
		}
		else{
			System.out.println("第"+runcount+"次接到来电");
		}*/			
	
	
	
// }

}

 

普通语音呼通率:

 

代码如下:匆匆忙忙写的,格式很乱,被注释的语句请忽略(或者删除),只看中文注释

package yuyin;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.core.UiWatcher;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class beijiao extends UiAutomatorTestCase {
	private static final long TIME_OUT = 10 * 60 * 1000;  
    private long currentTime;  
    private boolean flag = true;  
  
    long eslcape = 0; 
    
	public void testbeijiao() throws Exception{//Exception
	int count=1;
	int count1=1;

	UiObject JietingOne = new UiObject(new UiSelector().text("视频通话来电"));//��Ƶͨ������视频通话来电
//	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/videoCallIcon"));//��Ƶͨ������VOLET来电小图标

//1/	
	/*UiWatcher inComingWatcher = new MyWatcher();  
    getUiDevice().registerWatcher("来电", inComingWatcher);  
     
    getUiDevice().pressBack();  
//    UiObject dialButton = new UiObject(new UiSelector().resourceId("com.android.sprdlauncher1:id/workspace"));  
    System.out.println("waiting for incoming");  
    currentTime = System.currentTimeMillis();  
    while (flag && eslcape < TIME_OUT) {  
//    	VOLTEcall.clickAndWaitForNewWindow();  
    	Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
        eslcape = System.currentTimeMillis() - currentTime;  
    }  
    assertFalse("没有收到来电", flag);  
}  


class MyWatcher implements UiWatcher {  

//    @Override  
    public boolean checkForCondition() {  
//        UiObject inCall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/IncomingCallRejectButton"));  
    	UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
        while (eslcape < TIME_OUT) {  
            if (VOLTEcall.exists()) {  
                System.out.println("you have a call");  
                try {  
//                	VOLTEcall.clickAndWaitForNewWindow();  
                	System.out.println("22222222222");  
                	Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
                    flag = false;  
                    return true;  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
            eslcape = System.currentTimeMillis() - currentTime;  
        }  
        return false;  
    }  */
//1	

	
//2///
	//监听
	System.out.println("Log:00000000");
	for(int j = 1; j > 0; j++){//j = 0; j < 40; j++
		System.out.println("Log:aaaaaaaa");
	    UiDevice.getInstance().registerWatcher("phone", new UiWatcher() {
	    UiObject JietingOne = new UiObject(new UiSelector().text("来电"));//��Ƶͨ������视频通话来电
		UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/videoCallIcon"));//��Ƶͨ������VOLET来电小图标
		  public boolean checkForCondition() {
				System.out.println("Log:VOLTEcall wait");
				if(!JietingOne.exists()){
					try {
						System.out.println("Log:bbbbbbbbbbbb");
						Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
//						VOLTEcall.swipeRight(20);//接听
//						return true;
					} catch (Exception e) {
						// TODO: handle exception
					}
				  System.out.println("Log:YuYincall false");
	              return true;
				}
				System.out.println("Log:YuYincall success");
				return false;
			}
		});
	
		System.out.println("Log:1111111");
		sleep(10000);
	  if(!JietingOne.exists()){
		 System.out.println("Log:2222222");
		 sleep(1000);
//		 if(getUiDevice().isScreenOn()){//熄屏
//				getUiDevice().sleep();
//			}
//		 Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
//		 VOLTEcall.swipeRight(20);//接听	
	  }else{
		 System.out.println("Log:3333333"); 
//		 getUiDevice().sleep();//息屏
	   }
	}
}
	/*//监听来电
	UiDevice.getInstance().registerWatcher("phone", new UiWatcher() {
	 UiObject VOLTEcall = new UiObject(new UiSelector().resourceId("com.android.dialer:id/callStateLabel"));//��Ƶͨ������视频通话来电
	  public boolean checkForCondition() {
			// TODO Auto-generated method stub
			System.out.println("VOLTEcall laidian");
			if(VOLTEcall.exists()){
				try {
//					Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
					VOLTEcall.swipeRight(20);//接听
//					return true;
				} catch (Exception e) {
					// TODO: handle exception
				}
			  System.out.println("VOLTEcall success");
              return true;
			}
			System.out.println("VOLTEcall false");
			return false;
		}
	});*/
//2/	
	
	
	
	/*//�ж�来电判断
	Runtime.getRuntime().exec("mkdir sdcard/TestPresure");
	Runtime.getRuntime().exec("mkdir sdcard/TestPresure/CallRecording");
	if(JietingTwo.exists()){//JietingOne.getText().equals("视频通话来电")
//		sleep(20000);//休眠20秒接听
		Runtime.getRuntime().exec("input  keyevent  KEYCODE_CALL");//接听
		FileUtil.out("sdcard/CallRecording/VOLT接听成功.txt", "VOLTE接听成功次数"+count);
		count=count+1;
	}else{
		sleep(20000);//休眠20秒接听
		FileUtil.out("sdcard/GotaTestPresure/CallRecording/VOLTE接听失败.txt", "VOLTE接听失败次数"+count1);
		count1=count1+1;
	}*/

    
/*
	}
	
	
	//ImgCompare imgCompare = new ImgCompare();
	
//	@Override  
    protected void setUp() throws Exception {
		common.creatFile(getClass().getName());
		common.watcherTheError(getUiDevice(), getClass().getName());//运行错误报告监听器
    }  
//    @Override  
    protected void tearDown() throws Exception {  
          
    }  
	public void testDemo() throws UiObjectNotFoundException, RemoteException{
		try{
			callTwo();
		}catch(Exception e){
			common.takeshot(getUiDevice(), getClass().getName());
			e.printStackTrace();
			}
		finally{
			//getUiDevice().pressHome();
		}
	}
	public void callTwo() throws Exception {
		// 红牛系列
		Bundle bundle = getParams();
		String runcount = bundle.getString("runcount");
		System.out.println("被测试的设备名称是" + getUiDevice().getProductName());
		if (getUiDevice().getProductName().contains("e700")) {
			System.out.println("当前被测试的设备被判断为原生Android手机,执行图像对比判断");
			imgCompare();
		} else {
			// nubia系列
			// 如果20秒内没有看到来电界面,则算作失败
			for (int j = 0; j < 40; j++) {
				String CurrentPackageName =  getUiDevice().getCurrentPackageName();
				if (j == 39) {
					if(!getUiDevice().isScreenOn()){//截图前避免熄屏
						getUiDevice().wakeUp();
					}
					common.takeshotByDate(getUiDevice(), getClass().getName(),"The_"+runcount+"_time_call_fail_");
					System.out.println("第"+runcount+"次未接到来电-" + common.getDate());
				}
				if (CurrentPackageName.contains("incall")||CurrentPackageName.contains("phone")) {// 20秒内来电成功
					if(!getUiDevice().isScreenOn()){//截图前避免熄屏
						getUiDevice().wakeUp();
					}
					common.takeshotByDate(getUiDevice(), getClass().getName(),
							"The_"+runcount+"_time_call_success_");
					System.out.println("第"+runcount+"次接到来电");
					j = 41;
				} else {
					sleep(500);
				}
			}
			sleep(1000);
		}
	}
	
	 * 图片对比
	 
	public void imgCompare() throws RemoteException, UiObjectNotFoundException, FileNotFoundException{
		Bundle bundle = getParams();
		String runcount = bundle.getString("runcount");
		sleep(20000);//等待呼叫的时间20秒,由于红牛来电界面不规范只能通过截图对比
		String picName = "The_"+runcount+"_time_call_Rate_"+common.getDate();
		common.takeshot(getUiDevice(), getClass().getName(), picName);
		sleep(500);
		if (ImgCompare
			.sameAs("/storage/sdcard0/uiauto/CallBefore/Incall.png",
					"/storage/sdcard0/uiauto/CallTwo/" + picName
							+ ".png", 0.95)||ImgCompare
							.sameAs("/storage/sdcard0/uiauto/CallBefore/Incallblack.png",
									"/storage/sdcard0/uiauto/CallTwo/" + picName
											+ ".png", 0.99)) {//桌面截图和黑屏截图两次对比确认未收到来电
			System.out.println("第"+runcount+"次未接到来电-"+common.getDate());
		}
		else{
			System.out.println("第"+runcount+"次接到来电");
		}*/			
	
	
	
// }

//}


}