Search code examples
electroncypresschrome-devtools-protocol

Getting Cypress to run Headless Electron with Chrome DevTools Protocol


Cypress version ^3.8.3

Using Chrome I am able to setup and attached to the Remote Debugging Port.

In cypress/plugins/index.js

  if (browser.name === "chrome") {            
    args.push("--remote-debugging-port=9222");
    return args;
  }

When starting a cypress run I can then prefix with the environment variable CYPRESS_REMOTE_DEBUGGING_PORT=9222.

However, when I try and do similar with Electron, I never get a connection.

  if (browser.name === "electron") {
    args.webPreferences = {
      remoteDebuggingPort: 9222
    };
    //----OR------
    args.remoteDebuggingPort = 9222;
    return args;
  }

I feel like I'm missing something very simple! Any ideas on how to get Cypress Electron running the remote debug port, would be great!


Solution

  • Electron does not listen for CDP messages on a port, the method you are trying to use is restricted to using CDP with standalone browsers for now.


    However, if you just need to send CDP commands from your tests, and not subscribe to events, there is an undocumented and unsupported way to do that, via Cypress.automation('remote:debugger:protocol', { command, params }).

    Example: https://github.com/cypress-io/cypress/blob/d92d3c0bab21cbd4ff96c24848779461f183a6d6/packages/server/test/support/fixtures/projects/e2e/cypress/support/index.js#L1-L13