@@ -180,8 +180,6 @@ class TestContext {
180180 '--port=$chromeDriverPort ' ,
181181 '--url-base=$chromeDriverUrlBase ' ,
182182 ]);
183- // On windows this takes a while to boot up, wait for the first line
184- // of stdout as a signal that it is ready.
185183 final stdOutLines =
186184 chromeDriver.stdout
187185 .transform (utf8.decoder)
@@ -194,14 +192,31 @@ class TestContext {
194192 .transform (const LineSplitter ())
195193 .asBroadcastStream ();
196194
197- stdOutLines.listen (
198- (line) => _logger.finest ('ChromeDriver stdout: $line ' ),
199- );
195+ // Sometimes ChromeDriver can be slow to startup.
196+ // This was seen on a github actions run:
197+ // > 11:22:59.924700: ChromeDriver stdout: Starting ChromeDriver
198+ // > 139.0.7258.154 ([...]) on port 38107
199+ // > [...]
200+ // > 11:23:00.237350: ChromeDriver stdout: ChromeDriver was started
201+ // > successfully on port 38107.
202+ // Where in the 300+ ms it took before it was actually ready to accept
203+ // a connection we had tried - and failed - to connect.
204+ // We therefore wait until ChromeDriver reports that it has started
205+ // successfully.
206+
207+ final chromeDriverStartup = Completer ();
208+ stdOutLines.listen ((line) {
209+ if (! chromeDriverStartup.isCompleted &&
210+ line.contains ('was started successfully' )) {
211+ chromeDriverStartup.complete ();
212+ }
213+ _logger.finest ('ChromeDriver stdout: $line ' );
214+ });
200215 stdErrLines.listen (
201216 (line) => _logger.warning ('ChromeDriver stderr: $line ' ),
202217 );
203218
204- await stdOutLines.first ;
219+ await chromeDriverStartup.future ;
205220 } catch (e) {
206221 throw StateError (
207222 'Could not start ChromeDriver. Is it installed?\n Error: $e ' ,
0 commit comments