Skip to content

Commit 117d6e8

Browse files
authored
Reduce devtools_test.dart flakiness (#1086)
The `can not launch devtools for the same app in multiple tabs` test appears to be flaky because we attempt to launch DevTools before the page is fully loaded. There isn't a good asynchronous signal for this so as an alternative we wait for the page content to say `Hello World!`. This closes #1084.
1 parent d4e17c9 commit 117d6e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

dwds/test/devtools_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ final context = TestContext(
1414
path: 'append_body/index.html',
1515
);
1616

17+
Future<void> _waitForPageReady(TestContext context) async {
18+
var attempt = 100;
19+
while (attempt-- > 0) {
20+
var content = await context.webDriver.pageSource;
21+
if (content.contains('Hello World!')) return;
22+
await Future.delayed(const Duration(milliseconds: 100));
23+
}
24+
throw StateError('Page never initialized');
25+
}
26+
1727
void main() {
1828
group('Injected client', () {
1929
setUp(() async {
@@ -47,6 +57,9 @@ void main() {
4757
var devToolsWindow = windows[2];
4858
await newAppWindow.setAsActive();
4959

60+
// Wait for the page to be ready before trying to open DevTools again.
61+
await _waitForPageReady(context);
62+
5063
// Try to open devtools and check for the alert.
5164
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
5265
await Future.delayed(const Duration(seconds: 2));

0 commit comments

Comments
 (0)