如何将环境变量传递给颤振驱动程序测试

Gün*_*uer 13 dart flutter

我想将环境变量传递给flutter drive测试.

能够读取启动的应用程序或测试代码中的值都可以,因为我在应用程序中需要它,如果我只能在测试代码中获取它,我可以使用它将它传递给应用程序 driver.requestData()

例如,Travis允许我指定不以任何方式公开的环境变量(如脚本内容和日志输出).

我想以这种方式指定用户名和密码,以便在应用程序内部使用.

在Flutter中设置环境变量是一个类似的问题,但对于我的用例来说这似乎过于复杂.

Mat*_* S. 6

Platform.environment在运行驱动程序测试之前,我尝试使用Dart 读取环境变量,它似乎工作正常。下面是一个简单的示例,该示例使用FLUTTER_DRIVER_RESULTSenv变量设置测试摘要的输出目录。

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);
    });
  });
}
Run Code Online (Sandbox Code Playgroud)