uiautomation如何由用户自己输入内容(号码)和接收多参数内容

163 阅读2分钟

我们使用uiautomation时会涉及到呼叫电话的用例,但是这个号码又想让用户自己输入,那我们jar怎么接收用户自己输入的号码呢?

 

首先我们看看uiautomation如何获取外部参数的

		//接收用户输入内容
		 Bundle phone = getParams();
		 String phoneNumber=phone.getString("phone");//安装键值提取电话号码
		 System.out.println("phoneNumber:"+phoneNumber);

phoneNumber就是用户自己输入要呼叫的号码,至于用户输入正确或者为空情况,自己做判断,我这里就不讲解了;

 

我们生产jar包后,就是要执行,执行的时候带入参数进去就OK了

adb shell uiautomator runtest testAuto.jar --nohup -e phone 1883385438 -c com.dsy.MultiStressTest

这就把phone带入进jar里面了,phoneNumber就是接收;

说到这里,这个号码也是我们从执行命令写死的啊,不是用户自己输入的啊,别急,根据执行命令,我们用shell写个bat文本去执行,如下代码所示:



  set /p phone=请输入要呼叫的号码:
  echo "test is: %phone%"

  adb shell uiautomator runtest testAuto.jar --nohup -e phone %phone% -c com.dsy.MultiStressTest

-----------------------------------------------拓展知识---------------------------------------------------------------------

我们想由用户输入更多的参数呢?直接看代码步骤

jar内容:

		//接收用户输入内容
		 Bundle phone = getParams();
		 String phoneNumber=phone.getString("phone");//安装键值提取电话号码
		 System.out.println("phoneNumber:"+phoneNumber);

       //在获取另个参数
         Bundle phone2 = getParams();
		 String phoneNumber2=phone.getString("phone2");//安装键值提取电话号码
		 System.out.println("phoneNumber:"+phoneNumber2);

那uiautomation执行命令:

adb shell uiautomator runtest testAuto.jar --nohup -e phone 18838380438 -e phone2 15103056672 -c com.dsy.MultiStressTest

 

以此类推,我们由用户输入参数的方式还是通过写bat方式

 set /p phone=请输入要呼叫的号码:
  echo "test is: %phone%"

   set /p phone2=请输入要呼叫的号码2:
  echo "test is: %phone2%"

  adb shell uiautomator runtest testAuto.jar --nohup -e phone %phone% -e phone2 %phone2% -c com.dsy.MultiStressTest