Skip to content

API Controllers

Tobero edited this page Mar 13, 2023 · 3 revisions

DeviceActor


The device actor is a class that needs the device to be created. It doesn't provide any methods.

Activity


The Activity interface contains two properties. The appPackage and the activityPackage.

AppController


The AppController extends from the DeviceActor. The AppController contains methods for app controlling.

constructor(device: Device)

Creates a new instance of this controller

async openActivities(): Promise<Activity[]>

Get the currently opened activites. This will return a promise with an array of activities. This array will even include the paused activites.

Example

  console.log(await emulator.apps.openActivities());

installApp(pathToApp: string): Promise

Install an app from your local file system. The pathToApp parameter should point to the apk location, like path/to/app/appName.apk

async getActivities(packageName: string): Promise<Activity[]>

Returns a promise containing an array of all activities this package has. The package is just the identifier for your app.

startApp(packageName: string): Promise

This start the app with the package name provided. Returns a promise with a ExecResult

startActivity(activity: Activity): Promise

This starts a special activity of an app. This method should be preferred over the startApp method, as this method also wait until the app fully loaded before resolving the promise. Returns a promise with the ExecResult that will resolve when the app has fully loaded.

Example

  await emulator.apps.startActivity({
    appPackage: DefaultApps.CHROME,
    activityPackage: "org.chromium.chrome.browser.ChromeTabbedActivity"
  });

waitForActivity(activity: Activity, timeout: number = 200): Promise

This method returns a promise that gets resolved as soon as the required activity has been found. The timeout parameter is the time that passes before the check for the activity will be rerun

async isAppInstalled(packageName: string): Promise

Returns a promise with true or false, representing if the app has been installed on this device.

killApp(packageName: string): Promise

This method kills the app with the known package name. Returns a promise with the ExecResult

Example

  await emulator.apps.killApp(DefaultApps.CHROME);

async isAppRunning(packageName: string): Promise

This method returns a promise containig true or false. True when the package name is running. False when it isn't

FileController


The FileControllerextends from the DeviceActor. The FileController contains methods for controlling file uploads and downloads

constructor(device: Device)

Creates a new instance of this controller

async getFile(deviceFilePath: string, localFilePath: string): Promise

This method will copy the file from the device to your local machine. The deviceFilePath is the location on the device and the localFilePath is the path to the file on your computer (Which may not exit yet). Returns a promise containing the ExecResult

The file will get override if it exists.

async uploadFile(deviceFilePath: string, localFilePath: string): Promise

This method will copy the file from your machine to your device. The deviceFilePath is the location on the device (Which may not exit yet) and the localFilePath is the path to the file on your computer. Returns a promise containing the ExecResult

The file will get override if it exists.