Search code examples
flutterdartflutter-webflutter-integration-test

Flutter integration_test: How to automate multiple selection of widgets by long pressing shift key and mouse drag


I am trying to automate, in flutter web integration_test, wherein I want to select multiple widgets by long pressing shift key and mouse drag. May I know if this is possible, if yes, then how? or if not possible, then is there any alternate way to achieve this selection?

For reference, I have attached an image to get more clarity if my objective. enter image description here


Solution

  • To hold the shift you can try like this

    await simulateKeyDownEvent(LogicalKeyboardKey.shiftLeft);
    

    You can try creating a gesture then starting it based on location

    final Offset firstLocation = tester.getCenter(find.byKey('keyName'));
    final TestGesture gesture = await tester.startGesture(firstLocation, pointer: 5);
        await tester.pump();
    

    Then to drag you can use

    final Offset secondLocation = tester.getCenter(find.byKey('Key2Name'));
        await gesture.moveTo(secondLocation);
        await tester.pump();
    

    Then do gesuture.up

     await gesture.up();
    

    and to release shift you can do

    await simulateKeyUpEvent(LogicalKeyboardKey.shiftLeft);