integration_tests.dart 5.87 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
    '${flutterDirectory.path}/dev/integration_tests/channels',
    'lib/main.dart',
14
  ).call;
15 16
}

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

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

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

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

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

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

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

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

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

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
  ).call;
91 92
}

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

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

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

TaskFunction createEndToEndScreenshotTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/screenshot.dart',
118
  ).call;
119 120 121 122 123 124
}

TaskFunction createEndToEndKeyboardTextfieldTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/ui',
    'lib/keyboard_textfield.dart',
125
  ).call;
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
    '--dart-define=test.valueB=Value',
    ],
135
  ).call;
136 137
}

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

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

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

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);
    });
  }
}