Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add backgroundApp #988

Merged
merged 4 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/commands/app-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ export async function background(seconds) {
return await this.adb.startApp(args);
}

/**
* Puts the app to background and waits the given number of seconds then restores the app
* if necessary. The call is blocking.
*
* @this {AndroidDriver}
* @param {number} [seconds=-1] 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.
* @returns {Promise<void>}
*/
export async function mobileBackgroundApp (seconds = -1) {
await this.background(seconds);
}

/**
* @this {AndroidDriver}
* @param {import('../driver').AndroidDriverOpts?} [opts=null]
Expand Down
2 changes: 2 additions & 0 deletions lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
installAUT,
resetAUT,
background,
mobileBackgroundApp,
getCurrentActivity,
getCurrentPackage,
mobileClearApp,
Expand Down Expand Up @@ -413,6 +414,7 @@ class AndroidDriver
activateApp = activateApp;
queryAppState = queryAppState;
isAppInstalled = isAppInstalled;
mobileBackgroundApp = mobileBackgroundApp;

mobileGetUiMode = mobileGetUiMode;
mobileSetUiMode = mobileSetUiMode;
Expand Down
7 changes: 6 additions & 1 deletion lib/execute-method-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ export const executeMethodMap = {
required: ['appId'],
},
},

'mobile: backgroundApp': {
command: 'mobileBackgroundApp',
params: {
optional: ['seconds'],
}
},
'mobile: startService': {
command: 'mobileStartService',
params: {
Expand Down