当作业运行失败并显示E / launcher时,我需要在gitlab上运行ng e2e测试-进程退出,错误代码为199
8号角项目
首先,我将其安装在我的项目Puppeteer中
npm install puppeteer --save
这是我用于ng测试的karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome_no_sandbox'],
customLaunchers: {
Chrome_no_sandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
concurrency: Infinity,
singleRun: true
});
};
这是ng e2e的protractor.conf.js
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
chromeOptions: {
binary: require('puppeteer').executablePath(),
args: ['--headless', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
},
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
这是我的工作.gitlab-ci.yml
image: node:latest
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
before_script:
- apt-get update && apt-get install -y unzip fontconfig locales gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- npm cache clean --force
- npm install --silent && npm rebuild
stages:
- test
- build
unit_test:
stage: test
script: node_modules/.bin/ng test
e2e_test:
image: gnomeontherun/docker-node-chrome-headless:latest
stage: test
script: node_modules/.bin/ng e2e
release_job:
stage: build
script: node_modules/.bin/ng build --prod --aot
artifacts:
name: "project-$CI_COMMIT_REF_NAME"
paths:
- dist/
only:
- tags
这是我在gitlab上的错误
[01:57:35] I/launcher - Running 1 instances of WebDriver
[01:57:35] I/direct - Using ChromeDriver directly...
[01:57:35] E/launcher - unknown error: cannot find Chrome binary
(Driver info: chromedriver=75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}),platform=Linux 4.19.23-coreos-r1 x86_64)
[01:57:35] E/launcher - WebDriverError: unknown error: cannot find Chrome binary
(Driver info: chromedriver=75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}),platform=Linux 4.19.23-coreos-r1 x86_64)
at Object.checkLegacyResponse (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/selenium-webdriver/lib/http.js:509:13)
at /builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/selenium-webdriver/lib/http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:89:5)
From: Task: WebDriver.createSession()
at Function.createSession (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
at Function.createSession (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/selenium-webdriver/chrome.js:761:15)
at Direct.getNewDriver (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/protractor/built/driverProviders/direct.js:77:33)
at Runner.createBrowser (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/protractor/built/runner.js:195:43)
at /builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/protractor/built/runner.js:339:29
at _fulfilled (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/q/q.js:834:54)
at /builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/q/q.js:863:30
at Promise.promise.promiseDispatch (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/q/q.js:796:13)
at /builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/q/q.js:556:49
at runSingle (/builds/chetoui.mohamedaziz/angular-ci-cd-firebase/node_modules/q/q.js:137:13)
[01:57:35] E/launcher - Process exited with error code 199
答案 0 :(得分:0)
我与您分享我的配置,以便在本地和gitlab-ci上运行Angular项目的测试。这花费了我几天的工作,文档和许多很多的测试。
我的诀窍是定义一个配置,使我可以在本地成功运行单元和e2e测试,然后获得与Docker映像等效的配置并调整配置,直到一切顺利为止。我找不到一个将所有东西都放在一起的地方,我将许多零件放在一起以获得成功的配置,所以我很乐意分享我的结果。我希望它也能为您服务。
.gitlab-ci.yml
image: node:alpine
cache:
paths:
- node_modules/
stages:
- install
- test
install:
stage: install
before_script:
script:
- npm install
unit-test:
stage: test
before_script:
- apk add --no-cache chromium nss freetype freetype-dev harfbuzz ca-certificates ttf-freefont
- export CHROME_BIN=/usr/bin/chromium-browser
script:
- npm run test
e2e-test:
image: node:10
stage: test
before_script:
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee -a /etc/apt/sources.list
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- apt-get -qq update -y
- apt-get -qq install -y --allow-unauthenticated google-chrome-stable xvfb gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable imagemagick x11-apps default-jre
- Xvfb :0 -ac -screen 0 1024x768x24 &
- export DISPLAY=:99
- npm install
- node ./node_modules/protractor/bin/webdriver-manager update
script:
- npm run e2e --protractorConfig=protractor.conf.js
karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome_no_sandbox'],
customLaunchers: {
Chrome_no_sandbox: {
base: 'ChromeHeadless',
flags: ['--headless', '--no-sandbox']
}
},
concurrency: Infinity,
singleRun: true
});
};
protractor.conf.js
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox', '--headless', '--disable-extensions', '--disable-dev-shm-usage']
}},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};