waitForTarget method
This searches for a target in all browser contexts.
An example of finding a target for a page opened via window.open:
var newWindowTarget =
browser.waitForTarget((target) => target.url == 'https://example.com/');
await page.evaluate("() => window.open('https://example.com/')");
await newWindowTarget;
Implementation
Future<Target> waitForTarget(bool Function(Target) predicate,
{Duration? timeout}) {
timeout ??= const Duration(seconds: 30);
for (var target in targets) {
if (predicate(target)) return Future.value(target);
}
return StreamGroup.merge([
onTargetCreated,
onTargetChanged,
]).where(predicate).first.timeout(timeout);
}