@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
174 lines (173 loc) • 8.08 kB
TypeScript
type hideKeyboardStrategy = "pressKey" | "tapOutside" | "swipeDown" | "";
declare const ORIENTATION: {
readonly LANDSCAPE: "LANDSCAPE";
readonly PORTRAIT: "PORTRAIT";
readonly UNKNOWN: "UNKNOWN";
};
type Orientation = (typeof ORIENTATION)[keyof typeof ORIENTATION];
/**
* @class device
* @memberof mobile
*/
export declare class Device {
private vlf;
private ErrorHandler;
private isValidPlatform;
private executionPlatform;
/**
* @function isAppInstalled
* @memberof mobile.device
* @description Check if the application identified by its Package name/Bundle ID is installed on the device.
* @param {string} appPackageOrBundleId - Android package Name, or iOS bundle Id.
* @returns {boolean} - Returns `true` if specified app package/bundled installed in the device, or `false`.
* @example
* await mobile.device.isAppInstalled("com.google.android.apps.maps");
* await mobile.device.isAppInstalled("com.apple.AppStore")
*/
isAppInstalled(appPackageOrBundleId: string): Promise<boolean>;
/**
* @function installApp
* @memberof mobile.device
* @description Install the appropriate app based on the platform the test is being executed on.
* @param {string} appPath - Path of the app(.apk, .ipa)
* @returns {Promise<void>}
* @example
* await mobile.device.installApp("/path/to/your/app.apk");
* await mobile.device.installApp("/path/to/your/app.ipa");
*/
installApp(appPath: string): Promise<void>;
/**
* @function switchToContext
* @memberof mobile.device
* @description Switch to the specified( WEBVIEW | NATIVE_APP ) context if available.
* @param {string} [targetContext='WEBVIEW'] The name of the target context.
* @param {number} [timeout=5000] Maximum time to wait for the web context to appear, milliseconds.
* @returns {Promise<boolean>} Returns `true` if the context is successfully switched, otherwise `false`.
* @example
* await mobile.device.switchToContext();
* await mobile.device.switchToContext("NATIVE_APP", 1000);
*/
switchToContext(targetContext?: string, timeout?: number): Promise<boolean>;
/**
* @function getTargetContextIfAvailable
* @memberof mobile.device
* @description
* Returns the specified target context if available within a given timeout.
*
* This method retrieves the list of available contexts and determines if a context
* that matches the `targetContext` string is present. If the target context is found,
* it returns the context name; otherwise, it returns `null`.
*
* @param {string} [targetContext='WEBVIEW'] The name of the target context to check for.
* Common examples are `WEBVIEW` or `NATIVE_APP`.
* @param {number} [timeout=5000] The maximum time, in milliseconds, to wait for the target
* context to become available.
* @returns {Promise<string | null>} The name of the target context if found, or `null` if
* the context is not available within the timeout.
* @example
* const context = await getTargetContextIfAvailable("WEBVIEW", 10000);
* const context = await getTargetContextIfAvailable("NATIVE_APP", 10000);
*/
getTargetContextIfAvailable(targetContext?: string, timeout?: number): Promise<string | null>;
/**
* @function closeApplication
* @memberof mobile.device
* @description Close the currently active mobile application.
* @returns {Promise<void>}
* @example
* await mobile.device.closeApplication();
*/
closeApplication(): Promise<void>;
/**
* @function queryAppState
* @memberof mobile.device
* @description Queries the state of the application (e.g., running, background, not installed) on the mobile device(Android or iOS).
* @param {string} appPackageOrBundleId - Package name (Android) or bundle ID (iOS) of the application.
* @returns {Promise<number>} - The app state:
* 0 - Not running,
* 1 - Not installed,
* 2 - Running in the background (not suspended),
* 3 - Running in the background (suspended),
* 4 - Running in the foreground.
* @example
* await mobile.device.queryAppState("com.google.android.apps.maps");
* await mobile.device.queryAppState("com.apple.AppStore");
*/
queryAppState(appPackageOrBundleId: string): Promise<number>;
/**
* @function launchApp
* @memberof mobile.device
* @description Launches the app for both iOS and Android with a parameterized app identifier.
* @param {string} appPackageOrBundleId - The Android package name or iOS bundle ID of the application.
* @returns {Promise<void>} Resolves when the app is successfully launched.
* @example
* await mobile.device.launchApp("com.google.android.apps.maps");
* await mobile.device.launchApp("com.apple.AppStore");
*/
launchApp(appPackageOrBundleId: string): Promise<void>;
/**
* @function switchToLandscapeOrientation
* @memberof mobile.device
* @description Switches the device orientation to landscape mode.
* @returns {Promise<void>} Resolves when the orientation is successfully switched.
* @example
* await mobile.device.switchToLandscapeOrientation();
*/
switchToLandscapeOrientation(): Promise<void>;
/**
* @function switchToPortraitOrientation
* @memberof mobile.device
* @description Switches the device orientation to portrait mode.
* @returns {Promise<void>} Resolves when the orientation is successfully switched.
* @example
* await mobile.device.switchToPortraitOrientation();
*/
switchToPortraitOrientation(): Promise<void>;
/**
* @function getCurrentOrientation
* @memberof mobile.device
* @description Returns the device current orientation (PORTRAIT or LANDSCAPE)
* @returns {Promise<Orientation>} The current device orientation.
* @example
* await mobile.device.getCurrentOrientation();
*/
getCurrentOrientation(): Promise<Orientation>;
/**
* @function hideKeyboard
* @memberof mobile.device
* @description Hides the keyboard on both Android and iOS using specific strategies with timeout.
* @param {string} strategy - Strategy to use for hiding the keyboard ('pressKey', 'tapOutside', 'swipeDown').
* @param {string} key - Key to press if using the 'pressKey' strategy (e.g., 'Done', 'Enter').
* @param {number} keyCode - Key code for Android (optional).
* @param {number} [timeout=5000] - Timeout in milliseconds for retrying to hide the keyboard.
* @returns {Promise<void>}
* @example
* await mobile.device.hideKeyboard();
* await mobile.device.hideKeyboard('tapOutside');
* await mobile.device.hideKeyboard('swipeDown');
* //Android only, Sends a specific key code, like 66 for "Enter."
* await mobile.device.hideKeyboard('pressKey', undefined, 66);
* await mobile.device.hideKeyboard('pressKey', 'Done');
*/
hideKeyboard(strategy?: hideKeyboardStrategy, key?: string, keyCode?: number, timeout?: number): Promise<void>;
/**
* @function isKeyboardVisible
* @memberof mobile.device
* @description Checks if the keyboard is visible or not on the mobile device.
* @returns {Promise<boolean>} Returns `true` if the keyboard is visible on the mobile view.
* @example
* await mobile.device.isKeyboardVisible();
*/
isKeyboardVisible(): Promise<boolean>;
/**
* @function isPlatformSupported
* @memberof mobile.device
* @description Determine if the current platform is supported, if the current device platform is either `Android` or `iOS`.
* @returns {Promise<boolean>} If neither Android nor iOS is detected (e.g., Windows, Linux, or web), the condition evaluates to false
* @example
* await mobile.device.isPlatformSupported();
*/
isPlatformSupported(): Promise<boolean>;
}
declare const _default: Device;
export default _default;