老李分享:接电话扩展之uiautomator 2

时间:2023-03-09 01:32:10
老李分享:接电话扩展之uiautomator 2

主要的类就是上面的PhoneReceiver广播接收者。来电的时候,我们记录下电话号码,等该来电挂断以后,立即回拨给对方。配置文件如下:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.tm"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

<uses-permission android:name="android.permission.CALL_PHONE" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.tm.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<receiver android:name=".PhoneReceiver" >

<intent-filter>

<action android:name="android.intent.action.PHONE_STATE" />

<action android:name="android.intent.action.NEW_OUTGOING_CALL" />

</intent-filter>

</receiver>

</application>

</manifest>

这样我们就让该总机做到了立即回拨的功能。

缺点

1.该总机的号码要写死在case里或者case的配置文件里。当总机号码更换以后,用到该号码的case也会变化。当然如果在框架里去实现的话,也很简单。设定一个总机号码配置文档,这样,每次启动uiautomator case的时候,涉及到telephony模块的case都去该文档上读一下该号码即可,当然这得需要框架。

2.相对于APP测试来说,一般是测当在使用APP的过程中来一个电话的处理方式。用上面的方法可能不太好,因为你不能操作的过程中跑去打个电话,太麻烦。但是像我这样测系统的就好多了,因为我会专门测试telephony的功能,这样我就把打电话和接电话一起测了。