Uiautomator “am start”

后端 未结 3 774
一个人的身影
一个人的身影 2021-01-03 02:47

Does any body know how to call
am start -a ACTIVITY from uiautomator code.
Or is it possible to start activity right from junit

3条回答
  •  轮回少年
    2021-01-03 03:24

    It shoule be of with the following code. I use this in my test.

    UiDevice device = UiDevice.getInstance(getInstrumentation());
    final String TARGET_PACKAGE =
            InstrumentationRegistry.getTargetContext().getPackageName();
    
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);
    device.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), 5000);
    

提交回复
热议问题