gpt4 book ai didi

dart - 如何将环境变量传递到颤音驱动器测试

转载 作者:IT老高 更新时间:2023-10-28 12:31:16 26 4
gpt4 key购买 nike

我想将环境变量传递到 flutter驱动器测试。

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 驱动程序.requestdata()

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.

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

最佳答案

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

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

关于dart - 如何将环境变量传递到颤音驱动器测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46475450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com