integration_tests.dart 5.77 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import '../framework/devices.dart';
6
import '../framework/framework.dart';
7
import '../framework/task_result.dart';
8 9 10
import '../framework/utils.dart';

TaskFunction createChannelsIntegrationTest() {
11
  return DriverTest(
12 13 14 15 16
    '${flutterDirectory.path}/dev/integration_tests/channels',
    'lib/main.dart',
  );
}

17
TaskFunction createPlatformInteractionTest() {
18
  return DriverTest(
19 20 21 22 23
    '${flutterDirectory.path}/dev/integration_tests/platform_interaction',
    'lib/main.dart',
  );
}

24
TaskFunction createFlavorsTest() {
25
  return DriverTest(
26 27
    '${flutterDirectory.path}/dev/integration_tests/flavors',
    'lib/main.dart',
28
    extraOptions: <String>['--flavor', 'paid'],
29 30 31
  );
}

32 33 34 35 36 37 38 39
TaskFunction createIntegrationTestFlavorsTest() {
  return IntegrationTest(
    '${flutterDirectory.path}/dev/integration_tests/flavors',
    'integration_test/integration_test.dart',
    extraOptions: <String>['--flavor', 'paid'],
  );
}

40
TaskFunction createExternalUiIntegrationTest() {
41
  return DriverTest(
42 43 44 45 46
    '${flutterDirectory.path}/dev/integration_tests/external_ui',
    'lib/main.dart',
  );
}

47
TaskFunction createPlatformChannelSampleTest({String? deviceIdOverride}) {
48
  return DriverTest(
49 50
    '${flutterDirectory.path}/examples/platform_channel',
    'test_driver/button_tap.dart',
51
    deviceIdOverride: deviceIdOverride,
52 53 54
  );
}

55 56 57 58 59 60 61
TaskFunction createPlatformChannelSwiftSampleTest() {
  return DriverTest(
    '${flutterDirectory.path}/examples/platform_channel_swift',
    'test_driver/button_tap.dart',
  );
}

62
TaskFunction createEmbeddedAndroidViewsIntegrationTest() {
63
  return DriverTest(
64 65 66 67 68
    '${flutterDirectory.path}/dev/integration_tests/android_views',
    'lib/main.dart',
  );
}

69 70 71 72 73 74 75
TaskFunction createHybridAndroidViewsIntegrationTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/hybrid_android_views',
    'lib/main.dart',
  );
}

76
TaskFunction createAndroidSemanticsIntegrationTest() {
77
  return DriverTest(
78 79 80 81 82
    '${flutterDirectory.path}/dev/integration_tests/android_semantics_testing',
    'lib/main.dart',
  );
}

83
TaskFunction createIOSPlatformViewTests() {
84
  return DriverTest(
85
    '${flutterDirectory.path}/dev/integration_tests/ios_platform_view_tests',
86
    'lib/main.dart',
87 88 89
    extraOptions: <String>[
      '--dart-define=ENABLE_DRIVER_EXTENSION=true',
    ],
90 91 92
  );
}

93
TaskFunction createEndToEndKeyboardTest() {
94
  return DriverTest(
95 96 97 98 99
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/keyboard_resize.dart',
  );
}

100 101 102 103 104 105 106
TaskFunction createEndToEndFrameNumberTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/frame_number.dart',
  );
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
TaskFunction createEndToEndDriverTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/driver.dart',
  );
}

TaskFunction createEndToEndScreenshotTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/screenshot.dart',
  );
}

TaskFunction createEndToEndKeyboardTextfieldTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/keyboard_textfield.dart',
125 126 127
  );
}

128 129 130 131
TaskFunction dartDefinesTask() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/defines.dart', extraOptions: <String>[
132
    '--dart-define=test.valueA=Example,A',
133 134 135 136 137
    '--dart-define=test.valueB=Value',
    ],
  );
}

138 139 140 141 142 143 144
TaskFunction createEndToEndIntegrationTest() {
  return IntegrationTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'integration_test/integration_test.dart',
  );
}

145 146 147 148 149 150 151
TaskFunction createSpellCheckIntegrationTest() {
  return IntegrationTest(
    '${flutterDirectory.path}/dev/integration_tests/spell_check',
    'integration_test/integration_test.dart',
  );
}

152 153 154 155 156 157 158 159
TaskFunction createWindowsStartupDriverTest({String? deviceIdOverride}) {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/windows_startup_test',
    'lib/main.dart',
    deviceIdOverride: deviceIdOverride,
  );
}

160
class DriverTest {
161 162 163 164
  DriverTest(
    this.testDirectory,
    this.testTarget, {
      this.extraOptions = const <String>[],
165
      this.deviceIdOverride,
166 167
    }
  );
168 169 170

  final String testDirectory;
  final String testTarget;
171
  final List<String> extraOptions;
172
  final String? deviceIdOverride;
173 174

  Future<TaskResult> call() {
175
    return inDirectory<TaskResult>(testDirectory, () async {
176 177 178 179 180 181 182 183
      String deviceId;
      if (deviceIdOverride != null) {
        deviceId = deviceIdOverride!;
      } else {
        final Device device = await devices.workingDevice;
        await device.unlock();
        deviceId = device.deviceId;
      }
184 185
      await flutter('packages', options: <String>['get']);

186
      final List<String> options = <String>[
187
        '--no-android-gradle-daemon',
188 189 190 191 192
        '-v',
        '-t',
        testTarget,
        '-d',
        deviceId,
193
        ...extraOptions,
194
      ];
195
      await flutter('drive', options: options);
196

197
      return TaskResult.success(null);
198 199 200
    });
  }
}
201 202

class IntegrationTest {
203 204 205 206 207 208
  IntegrationTest(
    this.testDirectory,
    this.testTarget, {
      this.extraOptions = const <String>[],
    }
  );
209 210 211

  final String testDirectory;
  final String testTarget;
212
  final List<String> extraOptions;
213 214 215 216 217 218 219 220 221 222 223 224 225

  Future<TaskResult> call() {
    return inDirectory<TaskResult>(testDirectory, () async {
      final Device device = await devices.workingDevice;
      await device.unlock();
      final String deviceId = device.deviceId;
      await flutter('packages', options: <String>['get']);

      final List<String> options = <String>[
        '-v',
        '-d',
        deviceId,
        testTarget,
226
        ...extraOptions,
227 228 229 230 231 232 233
      ];
      await flutter('test', options: options);

      return TaskResult.success(null);
    });
  }
}