If you want to pass an environment variable to a flutter driver test? I tried using Dart’s Platform.environment to read in env variables before running driver tests and it seems to work fine. Below is a simple example that sets the output directory for the test summaries using the FLUTTER_DRIVER_RESULTS env variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import 'dart:async'; import 'dart:io' show Platform; import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart'; void main() { // Load environmental variables String resultsDirectory = Platform.environment['FLUTTER_DRIVER_RESULTS'] ?? '/tmp'; print('Results directory is $resultsDirectory'); group('increment button test', () { FlutterDriver driver; setUpAll(() async { // Connect to the app driver = await FlutterDriver.connect(); }); tearDownAll(() async { if (driver != null) { // Disconnect from the app driver.close(); } }); test('measure', () async { // Record the performance timeline of things that happen Timeline timeline = await driver.traceAction(() async { // Find the scrollable user list SerializableFinder incrementButton = find.byValueKey( 'increment_button'); // Click the button 10 times for (int i = 0; i < 10; i++) { await driver.tap(incrementButton); // Emulate time for a user's finger between taps await new Future<Null>.delayed(new Duration(milliseconds: 250)); } }); TimelineSummary summary = new TimelineSummary.summarize(timeline); summary.writeSummaryToFile('increment_perf', destinationDirectory: resultsDirectory, pretty: true); summary.writeTimelineToFile('increment_perf', destinationDirectory: resultsDirectory, pretty: true); }); }); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.