matmanjs / matman

Web 端对端测试(E2E,End-to-End Testing)解决方案
https://matmanjs.github.io/matman
MIT License
46 stars 10 forks source link

Error: Protocol error (Emulation.setDeviceMetricsOverride): Target closed. #232

Closed helinjiang closed 3 years ago

helinjiang commented 3 years ago
checkEntry.html:常规检查-安卓端活动主页
[BVT-自动化测试测试(start container)]        "before all" hook in "checkEntry.html:常规检查-安卓端活动主页":
[BVT-自动化测试测试(start container)]      Error: Protocol error (Emulation.setDeviceMetricsOverride): Target closed.
[BVT-自动化测试测试(start container)]       at /data/orange-ci/workspace/DevOps/matman-app/node_modules/puppeteer/lib/Connection.js:156:63
[BVT-自动化测试测试(start container)]       at new Promise (<anonymous>)
[BVT-自动化测试测试(start container)]       at CDPSession.send (DevOps/matman-app/node_modules/puppeteer/lib/Connection.js:155:16)
[BVT-自动化测试测试(start container)]       at EmulationManager.emulateViewport (DevOps/matman-app/node_modules/puppeteer/lib/EmulationManager.js:20:26)
[BVT-自动化测试测试(start container)]       at Page.setViewport (DevOps/matman-app/node_modules/puppeteer/lib/Page.js:669:58)
[BVT-自动化测试测试(start container)]       at Page.<anonymous> (DevOps/matman-app/node_modules/puppeteer/lib/helper.js:117:27)
[BVT-自动化测试测试(start container)]       at Page._screenshotTask (DevOps/matman-app/node_modules/puppeteer/lib/Page.js:770:24)
[BVT-自动化测试测试(start container)]       at processTicksAndRejections (internal/process/task_queues.js:97:5)
[BVT-自动化测试测试(start container)]     -- ASYNC --
[BVT-自动化测试测试(start container)]       at Page.<anonymous> (DevOps/matman-app/node_modules/puppeteer/lib/helper.js:116:19)
[BVT-自动化测试测试(start container)]       at PuppeteerRunner.runActions (DevOps/matman-app/node_modules/matman-runner-puppeteer/lib/PuppeteerRunner.js:283:33)
[BVT-自动化测试测试(start container)]       at PuppeteerRunner.getResult (DevOps/matman-app/node_modules/matman-runner-puppeteer/lib/PuppeteerRunner.js:338:24)
helinjiang commented 3 years ago

没有找到直接的原因,但是有一个高度怀疑的对象,就是设置设备的时候将 deviceScaleFactor=3 修改为 deviceScaleFactor=2 即可。

具体的说,例如我们使用 Galaxy Note 3 这个设备,它定义是:

{
    name: 'Galaxy Note 3',
    userAgent:
      'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
    viewport: {
      width: 360,
      height: 640,
      deviceScaleFactor: 3,
      isMobile: true,
      hasTouch: true,
      isLandscape: false,
    },
  }

将其中的 deviceScaleFactor 修改为 2 即可。另外,这个是只在 docker 环境里面出现这个问题,但是本地或者 linux 机器上都没这个问题。