waitForPage method

Future<void> waitForPage(
  1. String path, {
  2. Duration? timeout,
})

Waits for the current page to be path.

Implementation

Future<void> waitForPage(String path, {Duration? timeout}) async {
  final Duration limit = timeout ?? this.timeout;
  final Duration start = _clock.elapsed;
  while (true) {
    _checkStopped();
    final String? current = currentRouteName();
    if (current == path) {
      await _settle();
      return;
    }
    if (_clock.elapsed - start >= limit) {
      throw PlaybookFailure(
        'Still on ${current ?? 'an unnamed page'} after ${_seconds(limit)}, '
        'not $path.',
        visibleText: _tree().visibleText(),
      );
    }
    await _sleep(_poll);
  }
}