testUISleepUntilElement function

Future<bool> testUISleepUntilElement(
  1. Object? root,
  2. String selectors, {
  3. int? timeoutMs,
  4. int? intervalMs,
  5. int? minMs,
  6. Iterable<UIElement> mapper(
    1. List<UIElement> elems
    )?,
  7. bool validator(
    1. List<UIElement> elems
    )?,
  8. bool expected = false,
})

Calls testUISleepUntil checking if root has an UIElement matching selectors.

Implementation

Future<bool> testUISleepUntilElement(Object? root, String selectors,
    {int? timeoutMs,
    int? intervalMs,
    int? minMs,
    Iterable<UIElement> Function(List<UIElement> elems)? mapper,
    bool Function(List<UIElement> elems)? validator,
    bool expected = false}) {
  root ??= document.documentElement;

  if (root is! UIElement && root is! UIComponent) {
    throw ArgumentError("`root` is not an `UIElement` or `UIComponent`");
  }

  var stackTrace = StackTrace.current;

  return testUISleepUntil(
    () => _existsElement(root, selectors, mapper, validator),
    readyTitle: 'selectors: $selectors',
    timeoutMs: timeoutMs ?? 2000,
    intervalMs: intervalMs ?? 100,
    minMs: minMs,
  ).thenChain((ok) {
    if (expected && !ok) {
      Error.throwWithStackTrace(
          TestFailure("Expected element: `$selectors` ; root: `$root`"),
          stackTrace);
    }
    return ok;
  });
}