I was just recently starting to get this on projects after (at least I think that's why) I updated to Chrome 120.

      Could not open connection: unknown error: cannot find Chrome binary
        (Driver info: chromedriver=120.0.6099.71 (9729082fe6174c0a371fc66501f5efc5d69d3d2b-refs/branch-heads/6099_56@{#13}),platform=Linux 6.2.0-37-generic x86_64) (Behat\Mink\Exception\DriverException)

That's the error message in behat at least, which I think originates from the actual webdriver (chromedriver) response. If I look at the debug information from the chromedriver logs it says this:

[1703837483,910][INFO]: [0ca18bb59db30d5acd358de02a01da0a] RESPONSE InitSession ERROR unknown error: cannot find Chrome binary

Well the error is clear enough. It can not find the binary. That's fine by me, but where would I go about informing about the binary? Well, for me that would be in behat.yml:

@@ -33,8 +33,9 @@ default:
               w3c: false
           marionette: null
           chrome:
+            binary: /usr/bin/google-chrome
             switches:

Thanks to kostiukevych-ls in the comments, this seems like it would be something like this if you are on Mac OS:

@@ -33,8 +33,9 @@ default:
               w3c: false
           marionette: null
           chrome:
+            binary: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

This probably translates to something like this, while initiating the session with chromedriver (slightly edited for relevance and brevity):

[1703887172,675][INFO]: [95b2908582293fa560a7301661f5e741] COMMAND InitSession {
   "desiredCapabilities": {
      "chrome.binary": "/usr/bin/google-chrome",
      "chrome.extensions": [  ],
      "chrome.switches": [ "--ignore-certificate-errors", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage" ],
      "goog:chromeOptions": {
         "args": [ "--ignore-certificate-errors", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage" ],
         "binary": "/usr/bin/google-chrome",
         "extensions": [  ]
      },
      "ignoreZoomSetting": false,
      "marionette": true,
   }
}

If you are using some other tool that interacts with chromedriver, I am sure you are already setting some parameters there, which you could append this new parameter to.

Alternative solution, using browser name

For the attentive reader, you might contemplate over how practical it would be to have this change laying around locally. Good point. Chromedriver is actually supposed to find the chrome binary of itself, so why is it not in this case?

If you have some verbose logging enabled, you might notice this message also popping up:

[1708076533,081][DEBUG]: Unknown browser name: firefox

For me that was a bit surprising, since I did not ask for the firefox browser in any way I knew myself. However, since I am using behat using mink-selenium2-driver, firefox is actually set as the default browser name. If I am using chromedriver, it will try to use this value when it tries to find the binary.

To override it, all I needed to do was this (this is using the Drupal behat extension for the mink parameters):

diff --git a/behat.yml.dist b/behat.yml.dist
index 7bf8214b..958a9a25 100644
--- a/behat.yml.dist
+++ b/behat.yml.dist
@@ -21,6 +21,7 @@ default:
     Drupal\MinkExtension:
       files_path: '%paths.base%/tests/files'
       ajax_timeout: 15
+      browser_name: chrome

And voila. It now works both in CI environments and locally as well.