gpt4 book ai didi

vue.js - 在 gitlab-ci 中对 VueJS 应用程序进行端到端测试

转载 作者:搜寻专家 更新时间:2023-10-30 22:13:33 25 4
gpt4 key购买 nike

我已经使用 vue-cli 生成了一个 VueJS 项目,包括使用 Nightswatch.js 的端到端测试。

我正在使用以下 .gitlab-ci.yml 文件

services:
- selenium/standalone-chrome

stages:
- test
- pages

test:
image: node:6.11
stage: test
before_script:
- node -v
- npm -v
script:
- npm install
- npm test

pages:
image: node:6.11
stage: pages
before_script:
- node -v
- npm -v
script:
- npm install
- npm run build
- cp -R ./dist ./public
- cd ./public
- ls
artifacts:
paths:
- public
only:
- master

这是nightswatch.conf.js 文件

require('babel-register')
var config = require('../../config')

// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],

selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},

test_settings: {
default: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
}
},

chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},

firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}

在 Gitlab-CI 中,作业通过了,但查看日志时只有单元测试通过,而不是端到端测试。

> node test/e2e/runner.js

Starting selenium server...
An error occurred while trying to start Selenium. Check if JAVA is installed on your machine.
{ Error: spawn java ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
at onErrorNT (internal/child_process.js:376:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn java',
path: 'java',
spawnargs:
[ '-Dwebdriver.chrome.driver=/builds/Overdrivr/frontend/node_modules/chromedriver/lib/chromedriver/chromedriver',
'-jar',
'/builds/Overdrivr/frontend/node_modules/selenium-server/lib/runner/selenium-server-standalone-3.8.1.jar',
'-port',
4444 ] }
INFO Selenium process finished.
Job succeeded

如何正确配置 gitlab-ci 或 nightswatch 以在 Gitlab-CI 中运行端到端测试?

最佳答案

好的,现在我进一步查看了您的配置和撰写文件,我想我明白了您的问题。您需要做的第一件事是在 .yml 文件中为您的 selenium/standalone-chrome 服务命名。问题是您正在尝试在未安装 java 的测试容器(节点镜像)中独立启动 selenium。但是,selenium/standalone-chrome 图像可以,这是您要指向测试而不是 localhost

的地方
services:
"chrome"
- selenium/standalone-chrome

#...rest of file can stay the same

您需要做的第二件事是从您的 nightwatch 配置中完全删除 selenium 部分,并在您的 chrome 服务的 test_settings 下指向 selenium_host

selenium_host: 'chrome',

这是为我工作的 nightwatch.jsondocker-compose.yml

docker-compose.yml

version: '3'
services:
chrome:
image: selenium/standalone-chrome
tests:
image: nightwatch-tests
environment:
- ENV_PASS=${ENV_PASS}
depends_on:
- chrome

nightwatch.json

{
"src_folders": [
"nw_tests"
],
"output_folder": "nw_reports",
"page_objects_path": "./nw_tests/pages",
"globals_path": "globals.js",
"test_workers": false,
"test_settings": {
"default": {
"launchUrl": "https://mylaunchurl/login",
"selenium_port": 4444,
"selenium_host": "chrome",
"silent": true,
"screenshots": {
"enabled": true,
"path": "nw_screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args": ["deny-permission-prompts"],
"prefs": {
"profile.default_content_settings.popups": 0,
"download.prompt_for_download": false
}
}
}
}
}
}

关于vue.js - 在 gitlab-ci 中对 VueJS 应用程序进行端到端测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47708097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com