diff --git a/lib/desired-caps.js b/lib/desired-caps.js index 4397b3bd3..b767d9d06 100644 --- a/lib/desired-caps.js +++ b/lib/desired-caps.js @@ -130,6 +130,9 @@ let desiredCapConstraints = _.defaults({ useJSONSource: { isBoolean: true }, + enforceFreshSimulatorCreation: { + isBoolean: true + }, shutdownOtherSimulators: { isBoolean: true }, diff --git a/lib/driver.js b/lib/driver.js index 8253aed84..1432e9f11 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -734,31 +734,29 @@ class XCUITestDriver extends BaseDriver { return {device, realDevice: true, udid: this.opts.udid}; } - // figure out the correct simulator to use, given the desired capabilities - let device = await getExistingSim(this.opts); - - // check for an existing simulator - if (device) { - return {device, realDevice: false, udid: device.udid}; - } - - // no device of this type exists, so create one - log.info('Simulator udid not provided, using desired caps to create a new simulator'); if (!this.opts.platformVersion && this.iosSdkVersion) { log.info(`No platformVersion specified. Using latest version Xcode supports: '${this.iosSdkVersion}' ` + `This may cause problems if a simulator does not exist for this platform version.`); this.opts.platformVersion = this.iosSdkVersion; } - if (this.opts.noReset) { - // Check for existing simulator just with correct capabilities - let device = await getExistingSim(this.opts); + if (this.opts.enforceFreshSimulatorCreation) { + log.debug(`New simulator is requested. If this is not wanted, set 'enforceFreshSimulatorCreation' capability to false`); + } else { + // figure out the correct simulator to use, given the desired capabilities + const device = await getExistingSim(this.opts); + + // check for an existing simulator if (device) { return {device, realDevice: false, udid: device.udid}; } + + log.info('Simulator udid not provided'); } - device = await this.createSim(); + // no device of this type exists, or they request new sim, so create one + log.info('Using desired caps to create a new simulator'); + const device = await this.createSim(); return {device, realDevice: false, udid: device.udid}; } diff --git a/lib/simulator-management.js b/lib/simulator-management.js index 8135176db..eafcd8e10 100644 --- a/lib/simulator-management.js +++ b/lib/simulator-management.js @@ -5,6 +5,8 @@ import { resetXCTestProcesses } from './utils'; import _ from 'lodash'; import log from './logger'; import { tempDir, fs, mkdirp } from 'appium-support'; +import UUID from 'uuid-js'; + const INSTALL_DAEMON_CACHE = 'com.apple.mobile.installd.staging'; @@ -17,7 +19,7 @@ const INSTALL_DAEMON_CACHE = 'com.apple.mobile.installd.staging'; * @returns {object} Simulator object associated with the udid passed in. */ async function createSim (caps) { - const appiumTestDeviceName = `appiumTest-${caps.deviceName}`; + const appiumTestDeviceName = `appiumTest-${UUID.create().toString().toUpperCase()}-${caps.deviceName}`; const udid = await createDevice(appiumTestDeviceName, caps.deviceName, caps.platformVersion); return await getSimulator(udid); } diff --git a/test/functional/driver/driver-e2e-specs.js b/test/functional/driver/driver-e2e-specs.js index c46546a30..5dba4a204 100644 --- a/test/functional/driver/driver-e2e-specs.js +++ b/test/functional/driver/driver-e2e-specs.js @@ -15,14 +15,15 @@ const SIM_DEVICE_NAME = 'xcuitestDriverTest'; const should = chai.should(); chai.use(chaiAsPromised); -const getNumSims = async () => { +async function getNumSims () { return (await getDevices())[UICATALOG_SIM_CAPS.platformVersion].length; -}; -const deleteDeviceWithRetry = async function (udid) { +} + +async function deleteDeviceWithRetry (udid) { try { await retryInterval(10, 1000, deleteDevice, udid); } catch (ign) {} -}; +} describe('XCUITestDriver', function () { this.timeout(MOCHA_TIMEOUT); @@ -146,17 +147,16 @@ describe('XCUITestDriver', function () { }); }); - it.skip('default: creates sim and deletes it afterwards', async function () { - let caps = UICATALOG_SIM_CAPS; + it('default: creates sim and deletes it afterwards', async function () { + const caps = Object.assign({}, UICATALOG_SIM_CAPS, {enforceFreshSimulatorCreation: true}); - await killAllSimulators(); - let simsBefore = await getNumSims(); + const simsBefore = await getNumSims(); await initSession(caps); - let simsDuring = await getNumSims(); + const simsDuring = await getNumSims(); await deleteSession(); - let simsAfter = await getNumSims(); + const simsAfter = await getNumSims(); simsDuring.should.equal(simsBefore + 1); simsAfter.should.equal(simsBefore); diff --git a/test/unit/simulator-management-specs.js b/test/unit/simulator-management-specs.js index 10af34208..d00cf29fc 100644 --- a/test/unit/simulator-management-specs.js +++ b/test/unit/simulator-management-specs.js @@ -28,7 +28,7 @@ describe('simulator management', function () { await createSim(caps); createDeviceStub.calledOnce.should.be.true; - createDeviceStub.firstCall.args[0].should.eql('appiumTest-iPhone 6'); + /appiumTest-[\w-]{36}-iPhone 6/.test(createDeviceStub.firstCall.args[0]).should.be.true; createDeviceStub.firstCall.args[1].should.eql('iPhone 6'); createDeviceStub.firstCall.args[2].should.eql('10.1'); getSimulatorStub.calledOnce.should.be.true;