我需要在Google Cloud Build中运行cypress e2e测试。我刚运行id: End to End Test
时收到安装cypresss dependencies的错误。因此,我尝试下载依赖项,但这会发生:
E: Unable to locate package libasound2'
E: Unable to locate package libxss1
E: Unable to locate package libnss3
E: Unable to locate package libgconf-2-4
E: Unable to locate package libnotify-dev
E: Couldn't find any package by regex 'libgtk2.0-0'
E: Couldn't find any package by glob 'libgtk2.0-0'
E: Unable to locate package libgtk2.0-0
E: Unable to locate package xvfb
Reading state information...
Building dependency tree...
Reading package lists...
Status: Downloaded newer image for ubuntu:latest
Digest: sha256:eb70667a801686f914408558660da753cde27192cd036148e58258819b927395
latest: Pulling from library/ubuntu
Using default tag: latest
Pulling image: ubuntu
如何在Google Cloud Build中运行赛普拉斯?
cloudbuild.yaml
steps:
... npm setup ...
- name: 'ubuntu'
id: Install Cypress Dependencies
args:
[
'apt-get',
'install',
'xvfb',
'libgtk2.0-0',
'libnotify-dev',
'libgconf-2-4',
'libnss3',
'libxss1',
libasound2',
]
- name: 'gcr.io/cloud-builders/npm:current'
id: End to End Test
args: ['run', 'e2e:gcb']
答案 0 :(得分:1)
因此,您所拥有的问题是步骤应该彼此隔离。运行apt-get update
可以正常运行,但是当您尝试apt-get
安装所需的依赖项时,运行不会持久。在步骤之间仅保留项目目录中的数据(默认为/workspace
)。
我没有设法找到解决办法,而是使用Cypress Docker image成功地使Cypress在Google Cloud Build中运行。需要注意的一件事是,在workspace
步骤中,您还必须将Cypress安装缓存在npm install
文件夹中。您可能还想将.tmp
目录添加到您的.gcloudignore
- name: node
id: Install Dependencies
entrypoint: yarn
args: ['install']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'
然后您可以像这样运行测试
- name: docker
id: Run E2Es
args:
[
'run',
'--workdir',
'/e2e',
'--volume',
'/workspace:/e2e',
'--env',
'CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress',
'--ipc',
'host',
'cypress/included:3.2.0'
]
或者,如果您想运行自定义命令而不是默认的cypress run
,则可以
- name: docker
id: Run E2Es
args:
[
'run',
'--entrypoint',
'yarn',
'--workdir',
'/e2e',
'--volume',
'/workspace:/e2e',
'--env',
'CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress',
'--ipc',
'host',
'cypress/included:3.2.0',
'e2e',
]
让我们分解一下......
name: docker
告诉Cloud Build使用Docker Cloud Builder --workdir /e2e
告诉docker在运行期间使用容器中的/e2e
目录--volume /workspace:/e2e
将docker使用的/e2e
工作目录指向云构建使用的/workspace
工作目录--env CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress
告诉cypress指向/e2e/.tmp/Cypress
的Cypress缓存。--ipc host
修复了赛普拉斯在测试运行过程中崩溃的问题cypress/included:3.2.0
包含cypress和浏览器的Cypress Docker映像如果您正在运行自己的脚本,
--entrypoint yarn
会覆盖cypress/included
Dockerfile(记住是cypress run
)中的默认入口点e2e
是您要运行以运行e2es的脚本希望这会有所帮助!我花了一个多星期的时间试图使它正常工作,所以我想我会帮助其他面临相同问题的人:)
答案 1 :(得分:0)
不熟悉GCB,但是您可能需要先进行apt-get update
才能进行apt-get install
,请尝试:
steps:
... npm setup ...
- name: 'ubuntu'
id: Update apt index
args:
[
'apt-get',
'update',
]
- name: 'ubuntu'
id: Install Cypress Dependencies
args:
[
'apt-get',
'install',
'xvfb',
'libgtk2.0-0',
'libnotify-dev',
'libgconf-2-4',
'libnss3',
'libxss1',
'libasound2',
]
- name: 'gcr.io/cloud-builders/npm:current'
id: End to End Test
args: ['run', 'e2e:gcb']
另外,请注意,您在libasound2'
上有错字:)
答案 2 :(得分:0)
在 google cloud build 中运行 cypress 工作正常(现在):
steps:
# install dependencies
- id: install-dependencies
name: node
entrypoint: yarn
args: ['install']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'
# run cypress
- id: run-cypress
name: cypress/included:7.0.1
entrypoint: yarn
args: ['run', 'vue-cli-service', 'test:e2e', '--headless']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'
options:
machineType: 'E2_HIGHCPU_8'
注意:
cypress/included:latest
标签,因此标签需要保持更新E2_HIGHCPU_8
机器类型,默认仅提供 1 个 vCPU 和 4GBcypress/included
图像支持的任何内容