Knowledge Archiving and Sharing

无量心, 生福报, 无极限.

UiAutomator实现打电话功能

测试代码:

package com.yang.clicktest;

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.testrunner.UiAutomatorTestCase;

import android.os.Bundle;

public class UiClickTest7 extends UiAutomatorTestCase {
 
 // adb shell uiautomator runtest UiClickTest.jar --nohup -c com.yang.clicktest.UiClickTest7 -e phone 15212345678
 // call phone func
 
 @Override
 protected void setUp() throws Exception {
  // TODO Auto-generated method stub
  super.setUp();
  System.out.println("setUp..................");
 }

 @Override
 protected void tearDown() throws Exception {
  // TODO Auto-generated method stub
  super.tearDown();
  System.out.println("tearDown...............");
 }

 public void testProcess1() throws UiObjectNotFoundException{
  System.out.println("test 111...............");
  UiDevice.getInstance().pressHome();
  UiObject shouji = new UiObject(new UiSelector().text("Phone"));
  UiObject dialpad = new UiObject(new UiSelector().resourceId("com.android.contacts:id/dialpad"));
  
  shouji.clickAndWaitForNewWindow();
  dialpad.clickAndWaitForNewWindow();
  Bundle bundle = getParams();
  String phone = (String) bundle.get("phone");
  
  for(int i=0; i<phone.length();i++){
   char c=phone.charAt(i);
   String num=null;
   switch(c){
   case '0':
    num = "com.android.contacts:id/zero"; break;
   case '1':
    num = "com.android.contacts:id/one"; break;
   case '2':
    num = "com.android.contacts:id/two"; break;
   case '3':
    num = "com.android.contacts:id/three"; break;
   case '4':
    num = "com.android.contacts:id/four"; break;
   case '5':
    num = "com.android.contacts:id/five"; break;
   case '6':
    num = "com.android.contacts:id/six"; break;
   case '7':
    num = "com.android.contacts:id/seven"; break;
   case '8':
    num = "com.android.contacts:id/eight"; break;
   case '9':
    num = "com.android.contacts:id/nine"; break;
  
    
   }
   UiObject phoneNum=new UiObject(new UiSelector().resourceId(num));
   phoneNum.click();
   sleep(1000);
  }
  
  UiObject callButton = new UiObject(new UiSelector().resourceId("com.android.contacts:id/callbutton"));
  callButton.click();
  
/*  bundle.putString("key1", "value1");

  getAutomationSupport().sendStatus(10, bundle);
*/ }
 
/* public void testProcess2(){
  System.out.println("test 222...............");
 }*/

}


编译,并push  jar到data/local/tmp

...


运行:

adb shell uiautomator runtest UiClickTest.jar --nohup -c com.yang.clicktest.UiClickTest7 -e phone 110  // 拨打110




阅读更多
个人分类: Android 自动化测试
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭