在Docker容器中运行Cypress测试套件时,我收到以下错误:
自动化客户端已断开连接。无法继续运行测试。
使用此命令,在cypress/browsers:node12.6.0-chrome75
容器中运行:
cypress run --browser=chrome
这似乎是在shm空间用完时发生的。
默认情况下,Docker会创建一个/dev/shm
共享内存空间为64MB的容器。这对于Chrome来说通常太小,可能会导致Chrome崩溃。
我找到了两种解决方案:
- 禁用
/dev/shm
的使用:
// cypress/plugins/index.js
module.exports = (on, config) => {
// ref: https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'chrome') {
args.push('--disable-dev-shm-usage')
return args
}
return args
})
}
- 增加容器中
/dev/shm
的大小:
使用docker run --shm-size=1gb
(或您想要的任何大小(运行容器