flet-build-template/{{cookiecutter.out_dir}}/integration_test/app_test.dart

56 lines
1.8 KiB
Dart

import 'package:flet_integration_test/flet_integration_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:{{ cookiecutter.project_name }}/main.dart' as app;
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('end-to-end test', () {
testWidgets('test app', (tester) async {
const testerServerUrl = String.fromEnvironment('FLET_TEST_SERVER_URL');
late FlutterWidgetTester widgetTester;
if (testerServerUrl.isNotEmpty) {
debugPrint('Connecting to remote tester at $testerServerUrl');
widgetTester = await RemoteWidgetTester.connect(
tester: tester,
binding: binding,
serverUri: Uri.parse(testerServerUrl),
);
} else {
widgetTester = FlutterWidgetTester(tester, binding);
}
app.tester = widgetTester;
final args = <String>[];
const fletTestAppUrl = String.fromEnvironment('FLET_TEST_APP_URL');
if (fletTestAppUrl.isNotEmpty) {
args.add(fletTestAppUrl);
}
const fletTestPidFile = String.fromEnvironment('FLET_TEST_PID_FILE_PATH');
if (fletTestPidFile.isNotEmpty) {
args.add(fletTestPidFile);
}
const fletTestAssetsDir = String.fromEnvironment('FLET_TEST_ASSETS_DIR');
if (fletTestAssetsDir.isNotEmpty) {
args.add(fletTestAssetsDir);
}
app.main(args);
await Future<void>.delayed(const Duration(milliseconds: 500));
await widgetTester.pump(duration: const Duration(seconds: 1));
await widgetTester
.pumpAndSettle(duration: const Duration(milliseconds: 100));
await widgetTester.waitForTeardown();
});
});
}