How to pass an environment variable to a flutter driver test

前端 未结 3 2269
情书的邮戳
情书的邮戳 2021-02-19 03:50

I want to pass an environment variable to a flutter drive test.

Being able to read the value in the launched application or the test code would both be fi

3条回答
  •  清酒与你
    2021-02-19 04:09

    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.

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

提交回复
热议问题