appium-flutter-driver: Set timeout on flutter:scrollUntilVisible

When flutter:scrollUntilVisible can’t find the item, it goes on an infinite loop of waiting. It retries 3 times with a frequency of 60 and a timeout of 100000 milliseconds and after that, no other action is performed.

Flutter code

void main() {
  enableFlutterDriverExtension();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        key: const Key("list"),
        children: List.generate(
            18,
            (index) => Container(
                  key: Key(index.toString()),
                  height: 100,
                  color: Colors.primaries[index],
                )),
      ),
    );
  }
}

Appium Code Node.js

  const driver = await wdio.remote(opts);

  const list = find.byValueKey('list');

  index = 0;

  while (true) {
    console.log(index);
    var visible = true;

    const item = find.byValueKey(index + "");

    await driver.execute(
      "flutter:scrollUntilVisible",
      list,
      { "item": item, "dxScroll": 0, "dyScroll": -100}
    ).catch((_) => visible = false);

    if (!visible) {
      break;
    }

    await new Promise(resolve => setTimeout(resolve, 1000));

    index += 1;
  }

  //Scroll back to the first. This is visible in the log, but never executed
  await driver.execute(
    "flutter:scrollUntilVisible",
    list,
    { "item": find.byValueKey("0"), "dxScroll": 0, "dyScroll": 100 }
  );

  await new Promise(resolve => setTimeout(resolve, 10000));

  driver.deleteSession();

Appium version: 2.0.0-beta.46 Flutter driver version: flutter@1.10.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (9 by maintainers)

Most upvoted comments

1.13.0 has the change. The timeout name changed as waitTimeoutMilliseconds (changed the naming a bit) https://github.com/appium-userland/appium-flutter-driver/blob/main/driver/lib/commands/execute/scroll.ts

@KazuCocoa worked as expected. We’re good to go.