Skip to content

Fix Chrome being left with orphaned running tabs after each test

Each individual test method in a class extending ChromeDriverTestBase gets a new instance of ChromeDriver, which will start a new devtools connection and Chrome tab when the test visits a page.

These instances were not being stopped at the end of the test, meaning:

a) Progressively higher resource usage during the test run itself, even in CI (there are already 15 tests, so 15 open tabs by the end of the suite) which will continue to grow as more tests are added.

b) When iterating locally within a docker container, the long-running Chrome process continues to hold tabs open across multiple test runs, eventually consuming significant resources and causing tests to fail unexpectedly due to slow Chrome response times.

This commit stops the driver during teardown, causing Chrome to close the tab. It also removes the reference to the driver from the testcase instance itself, to allow PHP to garbage collect the driver & related objects between tests (phpunit testcases are held in memory for the duration of a test suite run).

Merge request reports