Search code examples
c#appiumappium-android

Appium - Which is best in case of relaunching App - LaunchApp Or StartActivity


I use Appium for testing Android device in C#.

Every time i run a test case, i need to go to Main screen and then begin the use case. This can be achieved in two ways, using: LaunchApp and StartActivity function.

As far as i believe, LaunchApp launches app again, that is killing the running app and start the app from the beginning. However i will end up in startup activity. This will free up memory space, so app will not go into stress or out of memory issues. StartActivity will not kill the App, but switch to particular activity. Which will be same as real case testing.

Is my above statement true? or what is the exact difference between the both?


Solution

  • In general you got it right, but it worth to add more context here.

    How it works:

    launchApp() by default does the following:

    • checks if app installed
    • performs fast reset (including app stop, cache cleanup, etc.)
    • starts the app with launch activity
    • checks package + activity to match the ones you set in capabilities (appWaitPackage, appWaitActivity)

    startActivity does the following:

    • runs command via adb shell to launch specified activity
    • checks package + activity to match the one you set as argument

    Real life examples, e.g. app that has LoginActivity -> NavigationActivity -> WhateverActivity flow:

    1. You were logged in to the app

    a) launchApp() will clean the app and move you back to LoginActivity

    b) startActivity(NavigationActivity) will just launch NavigationActivity, so you don't have to login to the app.

    1. You were not logged in to the app

    a) launchApp() will be same as in Q1

    b) startActivity(NavigationActivity) will fail with Incorrect package and activity as app flow does not allow it.

    I'm using startActivity before each test to get to start point, that helps to speedup tests suite by avoiding app reinstall and relogin multiple times.