1

Implementing some integration_test for flutter-web application wherein I'm trying to simulate mouse wheel scroll operation , I have SingleChildScrollView widget with series of Container in it...trying to scroll to end of the list?

I've tried the following without any success.

main.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));
    });
  });
}
Rajesh Patil
  • 181
  • 2
  • 10

0 Answers0