Skip to content

flutter_driver's waitUntilNoTransientCallbacks doesn't await Image asset loading #12243

@zzzev

Description

@zzzev

I have a screenshot test using flutter_driver where I'm taking a screenshot of a Widget which contains an Image widget which is created via new Image.asset('myasset.png', key: const Key('a')). The test code looks like this:

test('Widget with Image', () async {
      await driver.waitFor(find.byValueKey('a'));
      await driver.waitUntilNoTransientCallbacks();
      await scuba.diffScreenshot('opportunities');
    });

This takes a screenshot where the Image is in the tree (I can tell because it changes the alignment of the other elements in the Widget), but has not yet been loaded (it's blank). Very occasionally (<5% of the time), the test will take a screenshot where the image is loaded and visible.

If I add await new Future.delayed(const Duration(seconds: 1));, then the Image is always loaded, but this is likely wasting some amount of time and/or prone to flaking. I think that waitUntilNoTransientCallbacks is probably supposed to be await'ing whatever asset loading is happening in the background; if not, could we expose some other hook that would enable this?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: tests"flutter test", flutter_test, or one of our testsc: flakeTests that sometimes, but not always, incorrectly passt: flutter driver"flutter driver", flutter_drive, or a driver testtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions