TextExistsWithinStep function

StepDefinitionGeneric<World> TextExistsWithinStep()

Asserts the existence of text within a parent widget.

Examples:

Then I expect the text "Logout" to be present within the "user_settings_list" But I expect the text "Signup" to be absent within the "login_screen"

Implementation

StepDefinitionGeneric TextExistsWithinStep() {
  return then3<String, Existence, String, FlutterWorld>(
    RegExp(
        r'I expect the text {string} to be {existence} within the {string}$'),
    (text, exists, ancestorKey, context) async {
      final finder = context.world.appDriver.findByDescendant(
        context.world.appDriver.findBy(ancestorKey, FindType.key),
        context.world.appDriver.findBy(text, FindType.text),
        firstMatchOnly: true,
      );

      final isPresent = await context.world.appDriver.isPresent(
        finder,
      );

      context.expect(isPresent, exists == Existence.present);
    },
  );
}