Skip to content

Commit

Permalink
Added orientation to screenshots runtime env for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcc007 committed Jul 17, 2019
1 parent 8425787 commit d228757
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Config {
/// (called by screenshots)
@visibleForTesting
Future<void> storeEnv(Screens screens, String emulatorName, String locale,
String deviceType) async {
String deviceType, String orientation) async {
// store env for later use by tests
final screenProps = screens.screenProps(emulatorName);
final screenSize = screenProps == null ? null : screenProps['size'];
Expand All @@ -49,6 +49,7 @@ class Config {
'locale': locale,
'device_name': emulatorName,
'device_type': deviceType,
'orientation': orientation
};
await _envStore.writeAsString(json.encode(currentEnv));
}
Expand Down
23 changes: 17 additions & 6 deletions lib/src/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators,
final defaultLocale = 'en_US'; // todo: need actual locale of real device
print('Warning: the locale of a real device cannot be changed.');
await runProcessTests(config, screens, configDeviceName, defaultLocale,
deviceType, testPaths, deviceId, imageProcessor, runMode, archive);
deviceType, testPaths, deviceId, imageProcessor, runMode, archive, 'unknown');
} else {
// Function to check for a running android device or emulator
bool isRunningAndroidDeviceOrEmulator(Map device, Map emulator) {
Expand Down Expand Up @@ -258,8 +258,18 @@ Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators,
}

// run tests and process images
await runProcessTests(config, screens, configDeviceName, locale,
deviceType, testPaths, deviceId, imageProcessor, runMode, archive);
await runProcessTests(
config,
screens,
configDeviceName,
locale,
deviceType,
testPaths,
deviceId,
imageProcessor,
runMode,
archive,
deviceOrientation);
}

// if an emulator was started, revert locale if necessary and shut it down
Expand All @@ -286,11 +296,12 @@ Future runProcessTests(
String deviceId,
ImageProcessor imageProcessor,
RunMode runMode,
Archive archive) async {
Archive archive,
String orientation) async {
// store env for later use by tests
// ignore: invalid_use_of_visible_for_testing_member
await config.storeEnv(
screens, configDeviceName, locale, utils.getStringFromEnum(deviceType));
await config.storeEnv(screens, configDeviceName, locale,
utils.getStringFromEnum(deviceType), orientation);
for (final testPath in testPaths) {
print('Running $testPath on \'$configDeviceName\' in locale $locale...');
await utils.streamCmd('flutter', ['-d', deviceId, 'drive', testPath]);
Expand Down
4 changes: 3 additions & 1 deletion test/env_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ void main() {
final Config config = Config(configPath: 'test/screenshots_test.yaml');
final screens = await Screens();
await screens.init();
final orientation='orientation';

final env = {
'screen_size': '1440x2560',
'locale': 'en_US',
'device_name': 'Nexus 6P',
'device_type': 'android',
'orientation': orientation
};

// called by screenshots before test
await config.storeEnv(
screens, env['device_name'], env['locale'], env['device_type']);
screens, env['device_name'], env['locale'], env['device_type'], orientation );

// called by test
final Config testConfig = Config(configPath: 'test/screenshots_test.yaml');
Expand Down

0 comments on commit d228757

Please sign in to comment.