Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get multiple elements in flutter driver(QA environment)

I have been successfully using commonfinders to get a single element in flutter driver but when it comes to multiple elements which may have the same type, it always throws up an error. I understand this is by design. I would be grateful if someone could suggest a way to get multiple elements and store them in an array/list, So I can access them through their index. A similar functionality would be, in selenium, where it lets you use findElements(...) for multiple elements in contrast to findElement(...) which lets you search a single element.

like image 941
Deon Denis D'souza Avatar asked Mar 21 '18 05:03

Deon Denis D'souza


2 Answers

This is how to get first of elements by its type

find.descendant(
      of: find.byValueKey(parentWidgetKey),
      matching: find.byType('CheckBox'),
      firstMatchOnly: true,
);

If you have multiple checkboxes, just assign a key to their parent, get the parent by key, get the checkbox by type and set the firstMatchOnly flag to true

like image 130
tomrozb Avatar answered Sep 21 '22 23:09

tomrozb


The finders in flutter_driver are currently quite limited, in contrast to the finders provided by flutter_test. This is a known issue that will presumably be addressed someday: see https://github.com/flutter/flutter/issues/12810

In the meantime, as the ticket suggests, if you can assign a predictable key to your elements (e.g. my-el-01, my-el-02, my-el-03) then you can write a helper (findMyEl(String prefix, int maxEls)) that will try to find all the elements named per that scheme, and return as a list. :/

like image 42
ilikerobots Avatar answered Sep 19 '22 23:09

ilikerobots