我正在尝试使用Chrome的新无头浏览器模式在Travis ci上运行角度测试,但在使用npm run e2e
(ng e2e
)运行我的量角器e2e测试时遇到错误。使用npm test
(ng test --watch=false
)运行我的单元测试工作正常。
Travis Config:
sudo: false
dist: trusty
language: node_js
node_js:
- '6.11'
addons:
chrome: stable
install:
- npm install -g @angular/cli
- npm install
script:
- npm test
- npm run e2e
notifications:
webhooks:
on_success: change
on_failure: always
on_start: false
量角器配置:
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=800x600']
}
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
Travis错误
webpack: Compiled successfully.
[03:23:26] I/file_manager - creating folder /home/travis/build/kpfromer/smarttodo-angular/node_modules/protractor/node_modules/webdriver-manager/selenium
[03:23:26] I/update - chromedriver: unzipping chromedriver_2.35.zip
[03:23:27] I/update - chromedriver: setting permissions to 0755 for /home/travis/build/kpfromer/smarttodo-angular/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.35
[03:23:27] I/launcher - Running 1 instances of WebDriver
[03:23:27] I/direct - Using ChromeDriver directly...
[03:24:27] E/launcher - unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.12-041412-generic x86_64)
[03:24:27] E/launcher - WebDriverError: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.12-041412-generic x86_64)
at WebDriverError (/home/travis/build/kpfromer/smarttodo-angular/node_modules/selenium-webdriver/lib/error.js:27:5)
at Object.checkLegacyResponse (/home/travis/build/kpfromer/smarttodo-angular/node_modules/selenium-webdriver/lib/error.js:505:15)
at parseHttpResponse (/home/travis/build/kpfromer/smarttodo-angular/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/home/travis/build/kpfromer/smarttodo-angular/node_modules/selenium-webdriver/lib/http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
...
答案 0 :(得分:1)
谷歌浏览器的沙盒模式是一个问题,阻止了Chrome创建会话。
你需要禁用它。
示例量角器配置:
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=800,600', '--no-sandbox']
}
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};