App Service

Learn how to use BELLATRIX android app service.

Example

public class AppServiceTests extends AndroidTest {
    @Test
    public void testBackgroundApp() {
        app().appService().backgroundApp(1);
    }

    @Test
    public void testResetApp() {
        app().appService().resetApp();
    }

    @Test
    public void installAppInstalledFalse_When_AppIsUninstalled() throws URISyntaxException {
        URL appUrl = getClass().getClassLoader().getResource("Demos/ApiDemos.apk");
        File appFile = Paths.get(appUrl.toURI()).toFile();
        String appPath = appFile.getAbsolutePath();

        app().appService().installApp(appPath);

        app().appService().removeApp("com.example.android.apis");

        Assert.assertFalse(app().appService().isAppInstalled("com.example.android.apis"));

        app().appService().installApp(appPath);
        Assert.assertTrue(app().appService().isAppInstalled("com.example.android.apis"));
    }
}

Explanations

BELLATRIX gives you an interface to most common operations for controlling the Android app through the appService method. We already saw one of them startActivity for opening a particular initial activity.

app().appService().backgroundApp(1);

Backgrounds the app for the specified number of seconds.

app().appService().resetApp();

Resets the app.

Assert.assertTrue(app().appService().isAppInstalled("com.example.android.apis"));

Checks whether the app with the specified app package is installed.

app().appService().installApp(appPath);

Installs the APK file on the device.

app().appService().removeApp("com.example.android.apis");

Uninstalls the app with the specified app package.