为flutter-web应用程序实现一些集成测试,其中我试图模拟鼠标滚轮滚动操作,我有SingleChildScrollView
带有一系列容器的小部件......试图滚动到列表末尾?
我已经尝试了以下但没有任何成功。
主要.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
controller: ScrollController(),
scrollDirection: Axis.vertical,
child: Column(
children: [
Container(
height: 100,
width: double.infinity,
color: Colors.red,
),
Container(
height: 100,
width: double.infinity,
color: Colors.green,
),
Container(
height: 100,
width: double.infinity,
color: Colors.blue,
),
Container(
height: 100,
width: double.infinity,
color: Colors.purple,
),
Container(
height: 100,
width: double.infinity,
color: Colors.yellow,
),
Container(
height: 100,
width: double.infinity,
color: Colors.black12,
),
Container(
height: 100,
width: double.infinity,
color: Colors.orangeAccent,
),
Container(
height: 100,
width: double.infinity,
color: Colors.pink,
),
Container(
height: 100,
width: double.infinity,
color: Colors.amber,
),
],
)),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
app_test.dart
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:hello_world/main.dart' as app;
void main() async {
group('Complete E2E Test', () {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
app.main();
});
testWidgets('Hello World test', (WidgetTester tester) async {
final Offset scrollEventLocation = tester.getCenter(find.byType(SingleChildScrollView));
final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse);
testPointer.hover(scrollEventLocation);
final HitTestResult result = tester.hitTestOnBinding(scrollEventLocation);
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 200)));
await tester.sendEventToBinding(testPointer.scroll(const Offset(600, 200)));
await tester.pumpAndSettle(const Duration(seconds: 5));
});
});
}