appium / node-simctl

Node wrapper around Apple's simctl binary
Apache License 2.0
65 stars 30 forks source link

node-simctl

NPM version Downloads

Release

ES6/7 Node wrapper around Apple's simctl binary, the "Command line utility to control the iOS Simulator". simctl is run as a sub-command of xcrun

Installation

Install through npm.

npm install node-simctl

API

The module exports single class Simctl. This class contains methods which wrap the following simctl subcommands:

create (Create a new device)

clone (Clone an existing device)

None

upgrade (Upgrade a device to a newer runtime)

None

delete (Delete specified devices, unavailable devices, or all devices)

pair (Create a new watch and phone pair)

None

unpair (Unpair a watch and phone pair)

None

pair_activate (Set a given pair as active)

None

erase (Erase a device's contents and settings)

boot (Boot a device)

shutdown (Shutdown a device)

rename (Rename a device)

None

getenv (Print an environment variable from a running device)

openurl (Open a URL in a device)

addmedia (Add photos, live photos, videos, or contacts to the library of a device)

install (Install an app on a device)

uninstall (Uninstall an app from a device)

get_app_container (Print the path of the installed app's container)

launch (Launch an application by identifier on a device)

terminate (Terminate an application by identifier on a device)

spawn (Spawn a process by executing a given executable on a device)

list (List available devices, device types, runtimes, or device pairs)

icloud_sync (Trigger iCloud sync on a device)

None

pbsync (Sync the pasteboard content from one pasteboard to another)

None

pbcopy (Copy standard input onto the device pasteboard)

pbpaste (Print the contents of the device's pasteboard to standard output)

help (Prints the usage for a given subcommand)

None

io (Set up a device IO operation)

diagnose (Collect diagnostic information and logs)

None

logverbose (enable or disable verbose logging for a device)

None

status_bar (Set or clear status bar overrides)

None

ui (Get or Set UI options)

push (Send a simulated push notification)

privacy (Grant, revoke, or reset privacy and permissions)

keychain (Manipulate a device's keychain)

appinfo (Undocumented)

bootstatus (Undocumented)

Methods marked with the star (*) character do not require the udid property to be set on the Simctl instance upon their invocation. All other methods will throw an error if the udid property is unset while they are being invoked.

All public methods are supplied with docstrings that describe their arguments and returned values.

The Simctl class constructor supports the following options:

Advanced Usage

Any simctl subcommand could be called via exec method, which accepts the subcommand itself as the first argument and the set of options, which may contain additional command args, environment variables, encoding, etc. For example:

import Simctl from 'node-simctl';

const simctl = new Simctl();
const name = 'My Device Name';
simctl.udid = await simctl.createDevice(name, 'iPhone X', '13.3');
await simctl.bootDevice();
await simctl.startBootMonitor({timeout: 120000});
await simctl.exec('pbsync');
console.log(`Pasteboard content: ${await simctl.getPasteboard()}`);
const {stdout} = await simctl.exec('status_bar', {
  args: [simctl.udid, 'list']
});
console.log(output);
simctl.udid = void(await simctl.deleteDevice());

See specs for examples of usage.

Running Multiple Simulator SDKs On a Single Computer

It is possible to run multiple simulators using different Xcode SDKs on a single machine. Simply set a proper value to DEVELOPER_DIR environment variable for each process.

Read this MacOps article for more details.