Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('with udid booted: uses sim and leaves it afterwards', async function () {
// before
const udid = await createDevice();
let sim = await getSimulator(udid, {
platform: 'iOS',
checkExistence: false,
});
await sim.run();
await B.delay(2000);
// test
let caps = _.defaults({
udid,
noReset: true
}, UICATALOG_SIM_CAPS);
(await sim.isRunning()).should.be.true;
let simsBefore = await getNumSims();
await initSession(caps);
if (this.opts.platformVersion !== devicePlatform) {
this.opts.platformVersion = devicePlatform;
log.info(`Set platformVersion to '${devicePlatform}' to match the device with given UDID`);
}
await setupVersionCaps();
return {device, realDevice: false, udid: device.udid};
}
} else {
// make sure it is a connected device. If not, the udid passed in is invalid
const devices = await getConnectedDevices();
log.debug(`Available devices: ${devices.join(', ')}`);
if (!devices.includes(this.opts.udid)) {
// check for a particular simulator
log.debug(`No real device with udid '${this.opts.udid}'. Looking for simulator`);
try {
const device = await getSimulator(this.opts.udid);
return {device, realDevice: false, udid: this.opts.udid};
} catch (ign) {
throw new Error(`Unknown device or simulator UDID: '${this.opts.udid}'`);
}
}
}
const device = await getRealDeviceObj(this.opts.udid);
return {device, realDevice: true, udid: this.opts.udid};
}
// Now we know for sure the device will be a Simulator
await setupVersionCaps();
if (this.opts.enforceFreshSimulatorCreation) {
log.debug(`New simulator is requested. If this is not wanted, set 'enforceFreshSimulatorCreation' capability to false`);
} else {
before(async function () {
sim = await getExistingSim(DEVICE_NAME, PLATFORM_VERSION);
if (!sim) {
const udid = await createDevice(SIM_NAME, DEVICE_NAME, PLATFORM_VERSION);
sim = await getSimulator(udid);
simCreated = true;
}
// on certain system, particularly Xcode 11 on Travis, starting the sim fails
await retry(4, async function () {
try {
await sim.run({
startupTimeout: 60000,
});
} catch (err) {
await sim.shutdown();
throw err;
}
});
const port = await startHttpServer();
address = `http://localhost:${port}`;
if (!this.xcodeVersion) {
logger.debug('Setting Xcode version');
this.xcodeVersion = await utils.getAndCheckXcodeVersion(this.opts);
logger.debug(`Xcode version set to ${this.xcodeVersion.versionString}`);
}
logger.debug('Setting iOS SDK Version');
this.iosSdkVersion = await utils.getAndCheckIosSdkVersion();
logger.debug(`iOS SDK Version set to ${this.iosSdkVersion}`);
let timeout = _.isObject(this.opts.launchTimeout) ? this.opts.launchTimeout.global : this.opts.launchTimeout;
let availableDevices = await retry(3, instrumentsUtils.getAvailableDevices, timeout);
let iosSimUdid = await checkSimulatorAvailable(this.opts, this.iosSdkVersion, availableDevices);
this.sim = await getSimulator(iosSimUdid, this.xcodeVersion.versionString);
await moveBuiltInApp(this.sim);
this.opts.localizableStrings = await utils.parseLocalizableStrings(this.opts);
await utils.setBundleIdFromApp(this.opts);
await this.createInstruments();
{
// previously setDeviceInfo()
this.shouldPrelaunchSimulator = utils.shouldPrelaunchSimulator(this.opts, this.iosSdkVersion);
let dString = await getAdjustedDeviceName(this.opts);
if (this.caps.app) {
await utils.setDeviceTypeInInfoPlist(this.opts.app, dString);
}
after(async function () {
const sim = await getSimulator(caps.udid, {
platform: 'iOS',
checkExistence: false,
});
await shutdownSimulator(sim);
await deleteDeviceWithRetry(caps.udid);
});
after(async function () {
const sim = await getSimulator(caps.udid);
await shutdownSimulator(sim);
await deleteDeviceWithRetry(caps.udid);
});
async function getSocket (udid) {
const sim = await getSimulator(udid);
return await sim.getWebInspectorSocket();
}