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

chore: add launchApp via devicectl #2354

Merged
merged 24 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
41 changes: 41 additions & 0 deletions lib/devicectl.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,45 @@ export class Devicectl {
});
return JSON.parse(stdout).result.apps;
}


/**
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
* @typedef {Object} LaunchAppOptions
* @property {string} [bundleId] bundle id to launch
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
* @property {Record<string, string|number>} [env] environment variables for the launching app process
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
* @property {boolean} [terminateExisting] if terminating the already running app
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
* Launch the given bundle id application with the given environment variable.
* This method is over devicectl command, this it may take additional seconds to launch the app.
* Please use via WDA or via appium-ios-device as primary method to launch app if possible.
*
* @param {LaunchAppOptions} [opts={}] launching app with devicectl command options.
* @returns {Promise<void>}
* @throws {Error} If the launching app command fails. For example, the given bundle id did not exist.
*/
async launchApp(opts = {}) {
const {
bundleId,
env,
terminateExisting = false
} = opts;

if (!_.isString(bundleId)) {
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`'bundleId' is required to build the process launch command.`);
};

const subcommandOptions = [bundleId];

mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
if (terminateExisting) {
subcommandOptions.push('--terminate-existing');
};

if (!_.isEmpty(env)) {
subcommandOptions.push('--environment-variables', JSON.stringify(_.mapValues(env, (v) => _.toString(v))));
};

await this.execute(['device', 'process', 'launch'], { subcommandOptions });
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"appium-ios-device": "^2.5.4",
"appium-ios-simulator": "^5.5.1",
"appium-remote-debugger": "^11.0.0",
"appium-webdriveragent": "^7.3.0",
"appium-webdriveragent": "^8.0.0",
"appium-xcode": "^5.1.4",
"async-lock": "^1.4.0",
"asyncbox": "^3.0.0",
Expand Down
Loading