首页 > 解决方案 > 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!

标签: electroncypresschrome-devtools-protocol

解决方案


Electron 不会在端口上侦听 CDP 消息,您尝试使用的方法目前仅限于在独立浏览器中使用 CDP。


但是,如果您只需要从测试中发送 CDP 命令,而不是订阅事件,则有一种未记录且不受支持的方法可以通过Cypress.automation('remote:debugger:protocol', { command, params }).

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


推荐阅读