3

I am constructing a Android UI test using UIAutomator, hope to start the target app to be test and do some test actions on the UI. But when I use intent to start the app, it does not work (ie. it does not launch the target app on my real device, but the target app can be launched in MainActivity using startactivity())

Code_piece (in my androidTest Class):

// Launch the app
Context context = ApplicationProvider.getApplicationContext();
final Intent intent = context.getPackageManager()
        .getLaunchIntentForPackage("com.target");
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);

This code is just from officail instruction: https://developer.android.com/training/testing/ui-testing/uiautomator-testing

I don't know why it can't start the target app, and where the critical problem lies. Does it matters with how the intent to be set, or the package name? (the package could not be wrong because I use it to launch the target app successfully in MainActivity)

sumedhe
  • 934
  • 1
  • 13
  • 30
Daniel
  • 51
  • 1

0 Answers0