appium-android-driver
Version:
Android UiAutomator and Chrome support for Appium
225 lines • 11.3 kB
TypeScript
import type { AndroidDriver, AndroidDriverOpts } from '../driver';
import type { AppState, TerminateAppOpts } from './types';
import type { UninstallOptions, InstallOptions } from 'appium-adb';
export declare const APP_STATE: {
readonly NOT_INSTALLED: 0;
readonly NOT_RUNNING: 1;
readonly RUNNING_IN_BACKGROUND: 3;
readonly RUNNING_IN_FOREGROUND: 4;
};
export interface IsAppInstalledOptions {
/**
* The user ID for which to check the package installation.
* The `current` user id is used by default.
*/
user?: string;
}
/**
* Checks whether the specified application is installed on the device.
*
* @param appId The application package identifier to check.
* @param opts Optional parameters for the installation check.
* @returns `true` if the application is installed, `false` otherwise.
*/
export declare function isAppInstalled(this: AndroidDriver, appId: string, opts?: IsAppInstalledOptions): Promise<boolean>;
/**
* Checks whether the specified application is installed on the device.
*
* @param appId Application package identifier
* @param user The user ID for which the package is installed.
* The `current` user id is used by default.
* @returns `true` if the application is installed, `false` otherwise.
*/
export declare function mobileIsAppInstalled(this: AndroidDriver, appId: string, user?: string | number): Promise<boolean>;
/**
* Queries the current state of the specified application.
*
* The possible states are:
* - `APP_STATE.NOT_INSTALLED` (0): The application is not installed
* - `APP_STATE.NOT_RUNNING` (1): The application is installed but not running
* - `APP_STATE.RUNNING_IN_BACKGROUND` (3): The application is running in the background
* - `APP_STATE.RUNNING_IN_FOREGROUND` (4): The application is running in the foreground
*
* @param appId Application package identifier
* @returns The current state of the application as a numeric value.
*/
export declare function queryAppState(this: AndroidDriver, appId: string): Promise<AppState>;
/**
* Activates the specified application, bringing it to the foreground.
*
* This is equivalent to launching the application if it's not already running,
* or bringing it to the foreground if it's running in the background.
*
* @param appId Application package identifier
*/
export declare function activateApp(this: AndroidDriver, appId: string): Promise<void>;
/**
* Removes (uninstalls) the specified application from the device.
*
* @param appId The application package identifier to remove.
* @param opts Optional uninstall options. See {@link UninstallOptions} for available options.
* @returns `true` if the application was successfully uninstalled, `false` otherwise.
*/
export declare function removeApp(this: AndroidDriver, appId: string, opts?: Omit<UninstallOptions, 'appId'>): Promise<boolean>;
/**
* @param appId Application package identifier
* @param timeout The count of milliseconds to wait until the
* app is uninstalled.
* @param keepData Set to true in order to keep the
* application data and cache folders after uninstall.
* @param skipInstallCheck Whether to check if the app is installed prior to
* uninstalling it. By default this is checked.
*/
export declare function mobileRemoveApp(this: AndroidDriver, appId: string, timeout?: number, keepData?: boolean, skipInstallCheck?: boolean): Promise<boolean>;
/**
* Terminates the specified application.
*
* This method forcefully stops the application and waits for it to be terminated.
* It checks that all process IDs belonging to the application have been stopped.
*
* @param appId The application package identifier to terminate.
* @param options Optional termination options. See {@link TerminateAppOpts} for available options.
* @returns `true` if the application was successfully terminated, `false` if it was not running.
* @throws {Error} If the application is still running after the timeout period.
*/
export declare function terminateApp(this: AndroidDriver, appId: string, options?: TerminateAppOpts): Promise<boolean>;
/**
* Terminates the specified application.
*
* This method forcefully stops the application and waits for it to be terminated.
* It checks that all process IDs belonging to the application have been stopped.
*
* @param appId Application package identifier
* @param timeout The count of milliseconds to wait until the app is terminated.
* 500ms by default.
* @returns `true` if the application was successfully terminated, `false` if it was not running.
* @throws {Error} If the application is still running after the timeout period.
*/
export declare function mobileTerminateApp(this: AndroidDriver, appId: string, timeout?: number | string): Promise<boolean>;
/**
* Installs the specified application on the device.
*
* The application file will be configured and validated before installation.
* Supported file formats are: `.apk`, `.apks`.
*
* @param appPath The path to the application file to install.
* Can be a local file path or a URL.
* @param opts Optional installation options. See {@link InstallOptions} for available options.
*/
export declare function installApp(this: AndroidDriver, appPath: string, opts: Omit<InstallOptions, 'appId'>): Promise<void>;
/**
* @param appPath
* @param checkVersion
* @param timeout The count of milliseconds to wait until the app is installed.
* 20000ms by default.
* @param allowTestPackages Set to true in order to allow test packages installation.
* `false` by default.
* @param useSdcard Set to true to install the app on sdcard instead of the device memory.
* `false` by default.
* @param grantPermissions Set to true in order to grant all the
* permissions requested in the application's manifest automatically after the installation is completed
* under Android 6+. `false` by default.
* @param replace Set it to false if you don't want the application to be upgraded/reinstalled
* if it is already present on the device. `true` by default.
* @param noIncremental Forcefully disables incremental installs if set to `true`.
* Read https://developer.android.com/preview/features#incremental for more details.
* `false` by default.
*/
export declare function mobileInstallApp(this: AndroidDriver, appPath: string, checkVersion?: boolean, timeout?: number, allowTestPackages?: boolean, useSdcard?: boolean, grantPermissions?: boolean, replace?: boolean, noIncremental?: boolean): Promise<void>;
/**
* Clears the application data and cache for the specified application.
*
* This is equivalent to running `adb shell pm clear <appId>`.
* All user data, cache, and settings for the application will be removed.
*
* @param appId Application package identifier
*/
export declare function mobileClearApp(this: AndroidDriver, appId: string): Promise<void>;
/**
* Retrieves the name of the currently focused activity.
*
* @returns The fully qualified name of the current activity (e.g., 'com.example.app.MainActivity').
*/
export declare function getCurrentActivity(this: AndroidDriver): Promise<string>;
/**
* Retrieves the package name of the currently focused application.
*
* @returns The package identifier of the current application (e.g., 'com.example.app').
*/
export declare function getCurrentPackage(this: AndroidDriver): Promise<string>;
/**
* Puts the application in the background for the specified duration.
*
* If a negative value is provided, the app will be sent to background and not restored.
* Otherwise, the app will be restored to the foreground after the specified duration.
*
* @param seconds The number of seconds to keep the app in the background.
* A negative value means to not restore the app after putting it to background.
* @returns `true` if the app was successfully restored, or the result of `startApp` if restoration was attempted.
*/
export declare function background(this: AndroidDriver, seconds: number): Promise<string | true>;
/**
* Puts the app to background and waits the given number of seconds then restores the app
* if necessary. The call is blocking.
*
* @param seconds The amount of seconds to wait between putting the app to background and restoring it.
* Any negative value means to not restore the app after putting it to background.
*/
export declare function mobileBackgroundApp(this: AndroidDriver, seconds?: number): Promise<void>;
/**
* Resets the Application Under Test (AUT).
*
* The reset behavior depends on the driver options:
* - If `fastReset` is enabled: Stops the app and clears its data
* - If `fullReset` is enabled: Uninstalls and reinstalls the app
* - If neither is enabled: Only stops the app
*
* @param opts Optional driver options. If not provided, uses the current session options.
* @throws {Error} If `appPackage` is not specified or if the app cannot be reset.
*/
export declare function resetAUT(this: AndroidDriver, opts?: AndroidDriverOpts | null): Promise<void>;
/**
* Installs the Application Under Test (AUT) on the device.
*
* If `fullReset` is enabled, this will perform a full reset (uninstall and reinstall).
* Otherwise, it will install or upgrade the app if needed. If `fastReset` is enabled
* and the app was already installed, it will perform a fast reset after installation.
*
* @param opts Optional driver options. If not provided, uses the current session options.
* @throws {Error} If `app` or `appPackage` options are not specified.
*/
export declare function installAUT(this: AndroidDriver, opts?: AndroidDriverOpts | null): Promise<void>;
/**
* Installs multiple additional APK files on the device.
*
* All APKs are installed asynchronously in parallel. This is useful for installing
* dependencies or additional applications required for testing.
*
* @param otherApps An array of paths to APK files to install.
* Each path can be a local file path or a URL.
* @param opts Optional driver options. If not provided, uses the current session options.
*/
export declare function installOtherApks(this: AndroidDriver, otherApps: string[], opts?: AndroidDriverOpts | null): Promise<void>;
/**
* Uninstalls the specified packages from the device.
*
* If `appPackages` contains `'*'`, all third-party packages will be uninstalled
* (excluding packages in `filterPackages`).
*
* @param appPackages An array of package names to uninstall, or `['*']` to uninstall all third-party packages.
* @param filterPackages An array of package names to exclude from uninstallation.
* Only used when `appPackages` contains `'*'`.
*/
export declare function uninstallOtherPackages(this: AndroidDriver, appPackages: string[], filterPackages?: string[]): Promise<void>;
/**
* Retrieves a list of all third-party packages installed on the device.
*
* Third-party packages are those that are not part of the system installation.
* This is equivalent to running `adb shell pm list packages -3`.
*
* @param filterPackages An array of package names to exclude from the results.
* @returns An array of third-party package names, excluding those in `filterPackages`.
* Returns an empty array if the command fails.
*/
export declare function getThirdPartyPackages(this: AndroidDriver, filterPackages?: string[]): Promise<string[]>;
//# sourceMappingURL=app-management.d.ts.map