appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
86 lines • 3.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initSimulator = initSimulator;
exports.startSim = startSim;
exports.createSim = createSim;
const simulator_management_1 = require("../device/simulator-management");
const utils_1 = require("../utils");
const SHUTDOWN_OTHER_FEAT_NAME = 'shutdown_other_sims';
/**
* Boots and configures the selected Simulator for the current session.
*/
async function initSimulator() {
const device = this.device;
if (this.opts.shutdownOtherSimulators) {
this.assertFeatureEnabled(SHUTDOWN_OTHER_FEAT_NAME);
await simulator_management_1.shutdownOtherSimulators.bind(this)();
}
await this.startSim();
if (this.opts.customSSLCert) {
// Simulator must be booted in order to call this helper
await device.addCertificate(this.opts.customSSLCert);
this.logEvent('customCertInstalled');
}
if (await simulator_management_1.setSafariPrefs.bind(this)()) {
this.log.debug('Safari preferences have been updated');
}
if (await simulator_management_1.setLocalizationPrefs.bind(this)()) {
this.log.debug('Localization preferences have been updated');
}
const promises = ['reduceMotion', 'reduceTransparency', 'autoFillPasswords']
.filter((optName) => typeof this.opts[optName] === 'boolean')
.map((optName) => {
this.log.info(`Setting ${optName} to ${this.opts[optName]}`);
return device[`set${(0, utils_1.upperFirst)(optName)}`](this.opts[optName]);
});
await Promise.all(promises);
this.logEvent('simStarted');
}
/**
* Starts the selected Simulator with the configured startup options.
*/
async function startSim() {
const devicePreferences = {};
const runOpts = {
scaleFactor: this.opts.scaleFactor,
connectHardwareKeyboard: !!this.opts.connectHardwareKeyboard,
pasteboardAutomaticSync: this.opts.simulatorPasteboardAutomaticSync ?? 'off',
isHeadless: !!this.opts.isHeadless,
tracePointer: this.opts.simulatorTracePointer,
devicePreferences,
};
// add the window center, if it is specified
if (this.opts.simulatorWindowCenter) {
devicePreferences.SimulatorWindowCenter = this.opts.simulatorWindowCenter;
}
if (Number.isInteger(this.opts.simulatorStartupTimeout)) {
runOpts.startupTimeout = this.opts.simulatorStartupTimeout;
}
// This is to workaround XCTest bug about changing Simulator
// orientation is not synchronized to the actual window orientation
const orientation = typeof this.opts.orientation === 'string' && this.opts.orientation.toUpperCase();
switch (orientation) {
case 'LANDSCAPE':
devicePreferences.SimulatorWindowOrientation = 'LandscapeLeft';
devicePreferences.SimulatorWindowRotationAngle = 90;
break;
case 'PORTRAIT':
devicePreferences.SimulatorWindowOrientation = 'Portrait';
devicePreferences.SimulatorWindowRotationAngle = 0;
break;
}
await this.device.run(runOpts);
}
/**
* Creates a new Simulator matching the current session capabilities.
*
* @deprecated This command is deprecated and will be removed in a future version.
*/
async function createSim() {
this.lifecycleData.createSim = true;
// create sim for caps
const sim = await simulator_management_1.createSim.bind(this)();
this.log.info(`Created simulator with udid '${sim.udid}'.`);
return sim;
}
//# sourceMappingURL=simulator.js.map