如何将环境变量传递给Flutter驱动程序测试 [英] How to pass an environment variable to a flutter driver test

查看:82
本文介绍了如何将环境变量传递给Flutter驱动程序测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

能够读取启动的应用程序或测试代码中的值都很好,因为我在应用程序中需要它,并且如果我只能在测试代码中获得它,则可以使用driver.requestData()

Being able to read the value in the launched application or the test code would both be fine, because I need it in the application and if I could only get it in the test code, I could pass it to the application using driver.requestData()

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

For example Travis allows me to specify environment variables that are not exposed in any way (like script content and log output).

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

I want to specify username and password this way so to be used inside the application.

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

Setting environment variables in Flutter is a similar question, but that seems overly complicated for my use case.

推荐答案

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

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

这篇关于如何将环境变量传递给Flutter驱动程序测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆