假设我需要想jar包穿三个参数,String uiserName,String password,long runTime,则对应的命令应该如下:
uiautomator runtest TestLogin.jar-e userName CrystalChen -e runTime 1000000 -e password 123 --nohup -c com.example.TestLogin
下划线斜体部分则为对应的参数配置。
在你的UiautomatorTestCase中对应接受参数的地方应该书写如下:
public void test1() throws Exception { Bundle bundle=getParams();//获取键值对 String userName=bundle.getString("userName"); String password=bundle.getString("password"); long runTime=Long.parseLong(bundle.getString("runTime")); System.out.println(runTime+"======="+password+"========"+userName); }
第二种方法:
adb shell uiautomator runtest name.jar -e uid 123,12456,555,666 -c test.mytake
然后脚本中可以这样获取:
Bundle number=getParams();
String id=number.getString("uid");
if(id!=null&&!"".equals(id)){
String[] userid=id.split(",");
if(userid!=null&&!0==userid.length){
for(int i=0;i<userid.length;i++){
System.out.println(userid[i]);
}
}
}