appium-ios-simulator
Version:
iOS Simulator interface for Appium.
145 lines • 6.67 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimulatorXcode15 = void 0;
const support_1 = require("@appium/support");
const teen_process_1 = require("teen_process");
const path_1 = __importDefault(require("path"));
const lodash_1 = __importDefault(require("lodash"));
const bluebird_1 = __importDefault(require("bluebird"));
const simulator_xcode_14_1 = require("./simulator-xcode-14");
class SimulatorXcode15 extends simulator_xcode_14_1.SimulatorXcode14 {
constructor() {
super(...arguments);
/**
* @override
* @inheritdoc
*
* @param {string} bundleId - The bundle id of the application to be checked.
* @return {Promise<boolean>} True if the given application is installed.
*/
this.isAppInstalled = async (bundleId) => {
try {
const appContainer = await this.simctl.getAppContainer(bundleId);
return appContainer.endsWith('.app') && await support_1.fs.exists(appContainer);
}
catch {
// get_app_container subcommand fails for system applications,
// as well as the hidden appinfo command
return (await this._fetchSystemAppBundleIds()).has(bundleId);
}
};
/**
* Sets the increase contrast configuration for the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @param {string} value valid increase constrast configuration value.
* Acceptable value is 'enabled' or 'disabled' with Xcode 16.2.
* @returns {Promise<void>}
*/
this.setIncreaseContrast = async (value) => {
await this.simctl.setIncreaseContrast(value);
};
/**
* Retrieves the current increase contrast configuration value from the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @returns {Promise<string>} the contrast configuration value.
* Possible return value is 'enabled', 'disabled',
* 'unsupported' or 'unknown' with Xcode 16.2.
*/
this.getIncreaseContrast = async () => await this.simctl.getIncreaseContrast();
/**
* Sets content size for the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @param {string} value valid content size or action value. Acceptable value is
* extra-small, small, medium, large, extra-large, extra-extra-large,
* extra-extra-extra-large, accessibility-medium, accessibility-large,
* accessibility-extra-large, accessibility-extra-extra-large,
* accessibility-extra-extra-extra-large with Xcode 16.2.
* @returns {Promise<void>}
*/
this.setContentSize = async (value) => {
await this.simctl.setContentSize(value);
};
/**
* Retrieves the current content size value from the given simulator.
* This function can only be called on a booted simulator.
*
* @override
* @since Xcode SDK 15 (but lower xcode could have this command)
* @returns {Promise<string>} the content size value. Possible return value is
* extra-small, small, medium, large, extra-large, extra-extra-large,
* extra-extra-extra-large, accessibility-medium, accessibility-large,
* accessibility-extra-large, accessibility-extra-extra-large,
* accessibility-extra-extra-extra-large,
* unknown or unsupported with Xcode 16.2.
*/
this.getContentSize = async () => await this.simctl.getContentSize();
}
/**
* Retrives the full path to where the simulator system R/O volume is mounted
*
* @returns {Promise<string>}
*/
async _getSystemRoot() {
const simRoot = await this.simctl.getEnv('IPHONE_SIMULATOR_ROOT');
if (!simRoot) {
throw new Error('The IPHONE_SIMULATOR_ROOT environment variable value cannot be retrieved');
}
return lodash_1.default.trim(simRoot);
}
/**
* Collects and caches bundle indetifier of system Simulator apps
*
* @returns {Promise<Set<string>>}
*/
async _fetchSystemAppBundleIds() {
if (this._systemAppBundleIds) {
return this._systemAppBundleIds;
}
const appsRoot = path_1.default.resolve(await this._getSystemRoot(), 'Applications');
const fetchBundleId = async (appRoot) => {
const infoPlistPath = path_1.default.resolve(appRoot, 'Info.plist');
try {
const { stdout } = await (0, teen_process_1.exec)('/usr/libexec/PlistBuddy', [
'-c', 'print CFBundleIdentifier', infoPlistPath
]);
return lodash_1.default.trim(stdout);
}
catch {
return null;
}
};
const allApps = (await support_1.fs.readdir(appsRoot))
.filter((x) => x.endsWith('.app'))
.map((x) => path_1.default.join(appsRoot, x));
// @ts-ignore Typescript does not understand the below filter
this._systemAppBundleIds = new Set(await bluebird_1.default.all(allApps.map(fetchBundleId).filter(Boolean)));
return this._systemAppBundleIds;
}
/**
* @override
* @inheritdoc
*
* @returns {Promise<string>}
*/
async getLaunchDaemonsRoot() {
const simRoot = await this.simctl.getEnv('IPHONE_SIMULATOR_ROOT');
if (!simRoot) {
throw new Error('The IPHONE_SIMULATOR_ROOT environment variable value cannot be retrieved');
}
return path_1.default.resolve(await this._getSystemRoot(), 'System/Library/LaunchDaemons');
}
}
exports.SimulatorXcode15 = SimulatorXcode15;
//# sourceMappingURL=simulator-xcode-15.js.map
;