我目前正在尝试使用其CI / CD平台在Gitlab上运行我的E2E测试。
目前的问题是我不能同时运行我的开发服务器和cypress,以便可以运行E2E测试。
这是我当前的.gitlab-ci.yml
文件:
image: node
variables:
npm_config_cache: "$CI_PROJECT_DIR/.npm"
CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm
- cache/Cypress
- node_modules
stages:
- setup
- test
setup:
stage: setup
image: cypress/base:10
script:
- npm ci
# check Cypress binary path and cached versions
# useful to make sure we are not carrying around old versions
- npx cypress cache path
- npx cypress cache list
cypress:
stage: test
image: cypress/base:10
script:
# I need to start a dev server here in the background
- cypress run --record --key <my_key> --parallel
artifacts:
when: always
paths:
- cypress/videos/**/*.mp4
- cypress/screenshots/**/*.png
expire_in: 7 day
答案 0 :(得分:1)
在Cypress's official GitHub page中,example .gitlab-ci.yml
有一个running Cypress in continuous integration。
它使用命令npm run start:ci &
在后台运行开发服务器。
因此,您的.gitlab-ci.yml
可能看起来像这样:
⋮
cypress:
image: cypress/base:10
stage: test
script:
- npm run start:ci & # start the server in the background
- cypress run --record --key <my_key> --parallel
⋮
答案 1 :(得分:0)
或使用此实用程序启动服务器,等待URL响应,然后运行测试并关闭服务器https://github.com/bahmutov/start-server-and-test