一直在使用eclipse做android app的UI自动化测试,随着android版本的更新,eclipse在兼容高版本上不在兼顾,所以想转到用AS来实现,出于as和eclipse的不同,在代码实现对app的运行上略有不同,经过一番代码实现后,特将简易代码贴出,供像我这样的小白参考。 public class CommonHelper { private Context mContext = null; //launch app method //packageName:应用的包名 //mainName:待测app的MainActivity名字 public void launcApp(String packageName, String mainName) { mContext = InstrumentationRegistry.getInstrumentation().getContext(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName, mainName); intent.setComponent(cn); mContext.startActivity(intent); } }
Android Studio做自动化测试代码实现launch待测app
最新推荐文章于 2022-05-11 11:32:37 发布