From 67c858759f38a011d03c252db959a2a3c1255479 Mon Sep 17 00:00:00 2001 From: Maurice McCabe Date: Tue, 16 Jul 2019 19:45:24 -0700 Subject: [PATCH] Added extra time for locale change on emulator to allow for orientation change. Also added wait for simulator to boot #66 --- lib/src/daemon_client.dart | 14 ++++++++++++++ lib/src/run.dart | 13 ++++++++----- test/screenshots_test.dart | 21 ++++++--------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/src/daemon_client.dart b/lib/src/daemon_client.dart index ea802ff9..6f71675e 100644 --- a/lib/src/daemon_client.dart +++ b/lib/src/daemon_client.dart @@ -199,3 +199,17 @@ List iosDevices() { return device; }).toList(); } + +/// Wait for emulator or simulator to start +Future waitForEmulatorToStart( + DaemonClient daemonClient, String simulatorName) async { + bool started = false; + while (!started) { + final devices = await daemonClient.devices; + final device = devices.firstWhere( + (device) => device['name'] == simulatorName && device['emulator'], + orElse: () => null); + started = device != null; + await Future.delayed(Duration(milliseconds: 1000)); + } +} diff --git a/lib/src/run.dart b/lib/src/run.dart index c4c82538..65c5dafd 100644 --- a/lib/src/run.dart +++ b/lib/src/run.dart @@ -189,19 +189,19 @@ Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators, device['emulator'])) { // an already running simulator await setSimulatorLocale( - deviceId, configDeviceName, locale, stagingDir); + deviceId, configDeviceName, locale, stagingDir, daemonClient); } else { if (device == null && simulator != null) { if (pendingIosLocaleChangeAtStart) { // a non-running simulator await setSimulatorLocale( - deviceId, configDeviceName, locale, stagingDir, + deviceId, configDeviceName, locale, stagingDir, daemonClient, running: false); pendingIosLocaleChangeAtStart = false; } else { // a running simulator await setSimulatorLocale( - deviceId, configDeviceName, locale, stagingDir); + deviceId, configDeviceName, locale, stagingDir, daemonClient); } } } @@ -323,8 +323,8 @@ Map _findDevice(List devices, List emulators, String deviceName) { } /// Set the locale for a running simulator. -Future setSimulatorLocale( - String deviceId, String deviceName, String testLocale, stagingDir, +Future setSimulatorLocale(String deviceId, String deviceName, String testLocale, + String stagingDir, DaemonClient daemonClient, {bool running = true}) async { // a running simulator final deviceLocale = utils.getIosSimulatorLocale(deviceId); @@ -336,6 +336,7 @@ Future setSimulatorLocale( await _changeSimulatorLocale(stagingDir, deviceId, testLocale); print('Starting $deviceName...'); startSimulator(deviceId); + await waitForEmulatorToStart(daemonClient, deviceName); } } @@ -352,6 +353,8 @@ Future setEmulatorLocale(String deviceId, testLocale, deviceName) async { changeAndroidLocale(deviceId, deviceLocale, testLocale); // daemonClient.verbose = false; await utils.waitAndroidLocaleChange(deviceId, testLocale); + // allow additional time before orientation change + await Future.delayed(Duration(milliseconds: 5000)); } } diff --git a/test/screenshots_test.dart b/test/screenshots_test.dart index 8deef59c..bc4e382a 100644 --- a/test/screenshots_test.dart +++ b/test/screenshots_test.dart @@ -391,11 +391,15 @@ void main() { // unpack resources await resources.unpackScripts(stagingDir); + final daemonClient = DaemonClient(); + await daemonClient.start; + // change locale final simulatorInfo = utils.getHighestIosSimulator(utils.getIosSimulators(), simulatorName); final deviceId = simulatorInfo['udid']; - await run.setSimulatorLocale(deviceId, simulatorName, locale, stagingDir, + await run.setSimulatorLocale( + deviceId, simulatorName, locale, stagingDir, daemonClient, running: false); // start simulator @@ -696,7 +700,7 @@ devices: final scriptDir = 'lib/resources/script'; final simulatorName = 'iPhone 7 Plus'; final simulatorInfo = - utils.getHighestIosSimulator(utils.getIosSimulators(), simulatorName); + utils.getHighestIosSimulator(utils.getIosSimulators(), simulatorName); final deviceId = simulatorInfo['udid']; run.startSimulator(deviceId); final daemonClient = DaemonClient(); @@ -734,16 +738,3 @@ devices: }); }); } - -Future waitForEmulatorToStart( - DaemonClient daemonClient, String simulatorName) async { - bool started = false; - while (!started) { - final devices = await daemonClient.devices; - final device = devices.firstWhere( - (device) => device['name'] == simulatorName && device['emulator'], - orElse: () => null); - started = device != null; - await Future.delayed(Duration(milliseconds: 1000)); - } -} \ No newline at end of file