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




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值