waitForTextContains method

Future<void> waitForTextContains({
  1. String? text,
  2. List<String> anyOf = const [],
  3. required int timeoutMs,
})

Implementation

Future<void> waitForTextContains({
  String? text,
  List<String> anyOf = const [],
  required int timeoutMs,
}) async {
  final textCandidates = <String>[
    if (text != null && text.trim().isNotEmpty) text,
    ...anyOf.where((value) => value.trim().isNotEmpty),
  ];
  if (textCandidates.isEmpty) {
    throw EnsembleTestFailure(
      'expectTextContains requires "text" or "anyOf"',
    );
  }

  final stopwatch = Stopwatch()..start();
  while (stopwatch.elapsedMilliseconds < timeoutMs) {
    await _pump(
        duration: config.waitPollInterval, label: 'expectTextContains');
    if (assertions.isAnyTextContainingVisible(textCandidates)) {
      return;
    }
  }

  throw EnsembleTestFailure(
    'Timed out after ${timeoutMs}ms waiting for text containing one of: '
    '${textCandidates.map((t) => '"$t"').join(', ')}. '
    '${assertions.textFailureHint(textCandidates)}',
  );
}