Skip to content

Commit

Permalink
Added extra time for locale change on emulator to allow for orientation
Browse files Browse the repository at this point in the history
change. Also added wait for simulator to boot mmcc007#66
  • Loading branch information
mmcc007 committed Jul 17, 2019
1 parent 81ca719 commit 67c8587
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
14 changes: 14 additions & 0 deletions lib/src/daemon_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
13 changes: 8 additions & 5 deletions lib/src/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -336,6 +336,7 @@ Future setSimulatorLocale(
await _changeSimulatorLocale(stagingDir, deviceId, testLocale);
print('Starting $deviceName...');
startSimulator(deviceId);
await waitForEmulatorToStart(daemonClient, deviceName);
}
}

Expand All @@ -352,6 +353,8 @@ Future<void> 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));
}
}

Expand Down
21 changes: 6 additions & 15 deletions test/screenshots_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 67c8587

Please sign in to comment.