diff --git a/packages/react-native-editor/__device-tests__/helpers/caps.js b/packages/react-native-editor/__device-tests__/helpers/caps.js index 804ef802fb5c4..a71916c83a660 100644 --- a/packages/react-native-editor/__device-tests__/helpers/caps.js +++ b/packages/react-native-editor/__device-tests__/helpers/caps.js @@ -14,6 +14,7 @@ const ios = { exports.iosLocal = { ...ios, deviceName: 'iPhone 11', + wdaLaunchTimeout: 240000, }; exports.iosServer = { diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 50654b582ee43..8810756ee7a86 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -55,6 +55,18 @@ const isLocalEnvironment = () => { return testEnvironment.toLowerCase() === 'local'; }; +const getIOSPlatformVersions = () => { + const { runtimes = [] } = JSON.parse( + childProcess.execSync( 'xcrun simctl list runtimes --json' ).toString() + ); + + return runtimes + .reverse() + .filter( + ( { name, isAvailable } ) => name.startsWith( 'iOS' ) && isAvailable + ); +}; + // Initialises the driver and desired capabilities for appium const setupDriver = async () => { const branch = process.env.CIRCLE_BRANCH || ''; @@ -105,6 +117,28 @@ const setupDriver = async () => { desiredCaps.app = `sauce-storage:Gutenberg-${ safeBranchName }.app.zip`; // App should be preloaded to sauce storage, this can also be a URL if ( isLocalEnvironment() ) { desiredCaps = _.clone( iosLocal ); + + const iosPlatformVersions = getIOSPlatformVersions(); + if ( iosPlatformVersions.length === 0 ) { + throw new Error( + 'No iOS simulators available! Please verify that you have iOS simulators installed.' + ); + } + // eslint-disable-next-line no-console + console.log( + 'Available iOS platform versions:', + iosPlatformVersions.map( ( { name } ) => name ) + ); + + if ( ! desiredCaps.platformVersion ) { + desiredCaps.platformVersion = iosPlatformVersions[ 0 ].version; + + // eslint-disable-next-line no-console + console.log( + `Using iOS ${ desiredCaps.platformVersion } platform version` + ); + } + desiredCaps.app = path.resolve( localIOSAppPath ); } }