我正在为网站前端开发一个 Vue.js 应用程序。
对于这个应用程序,我想使用单元和 E2E 测试。我用 vue-cli 构建了我的项目.
据我了解,vue-cli 使用 Karma 进行单元测试,使用 Nightwatch + Selenium 进行 E2E 测试。
我的 .gitlab-ci.yml
如下所示:
stages:
- test
test:express:
image: node:boron
stage: test
script:
- cd backend/
- npm install --progress=false
- ./node_modules/.bin/jasmine
test:vue:
image: node:boron
stage: test
script:
- cd frontend/
- npm install --progress=false
- npm test
npm test
运行 e2e 和单元测试并在本地计算机上运行。单元测试运行顺利,Selenium 会打开 Chrome 窗口并使用 E2E 测试。
问题是不知道如何在 GitLab CI 上运行 E2E Selenium 测试。它一直给我一个错误说:
无法连接到 Selenium 服务器。您是否已经启动了 Selenium 服务器?
,虽然它之前说了两行,但它已经创建了一个 Selenium 服务器。
如何在 GitLab CI 上运行 E2E Selenium 测试?如果这无法实现,我可以在 GitLab CI 上运行哪种 E2E?
最佳答案
CI 脚本:
- npm install wget
- https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- apt install -y ./google-chrome-stable_current_amd64.deb apt-get
- 安装 -y default-jdk
- npm run test:e2e:headless
package.json:
test:e2e:headless : "vue-cli-service test:e2e --config ./tests/e2e/main-test/nightwatch.conf.js --env chromeHeadless"
“依赖”:{ “chromedriver”:“2.46.0”, “ Selenium 服务器”:“3.9.0” }
守夜人配置:
selenium: {
start_process: true,
server_path: require('selenium-server').path,
port: 4449,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4449,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + config.devServer.port
}
},
chromeHeadless: {
desiredCapabilities: {
browserName: 'chromeHeadless',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
args: [
'headless',
'disable-gpu',
'no-sandbox'
]
}
}
}
关于unit-testing - 如何使用 GitLab CI 设置 Selenium E2E 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47542709/