由于关于GitLab CI配置和Selenium的文档通常很差,我正在寻求帮助。
按兴趣点配置:
gitlab.ci.yml
:
image: node:7
variables:
HUB_PORT_4444_TCP_ADDR: "selenium__hub"
HUB_PORT_4444_TCP_PORT: "4444"
services:
- selenium/hub:latest
- selenium/node-phantomjs:latest
stages:
- test
test:
stage: test
before_script:
- apt-get update
- apt-get install -y default-jdk default-jre
- npm install -s -g @angular/cli@1.0.6
- npm install -s
- node ./node_modules/protractor/bin/webdriver-manager update
script:
- ./node_modules/.bin/protractor protractor.ci.conf.js
protractor.ci.conf.js
:
/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': './node_modules/phantomjs-prebuilt/bin/phantomjs'
},
directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
seleniumAddress: 'http://selenium__hub:4444/wd/hub'
};
使用上述配置,GitLab失败并显示:
$ ./node_modules/.bin/protractor protractor.ci.conf.js
(node:3702) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[09:53:27] I/launcher - Running 1 instances of WebDriver
[09:53:27] I/hosted - Using the selenium server at http://selenium__hub:4444/wd/hub
[09:53:28] E/launcher - Error forwarding the new session Empty pool of VM for setup Capabilities [{phantomjs.binary.path=./node_modules/phantomjs-prebuilt/bin/phantomjs, count=1, browserName=phantomjs}]
[09:53:28] E/launcher - WebDriverError: Error forwarding the new session Empty pool of VM for setup Capabilities [{phantomjs.binary.path=./node_modules/phantomjs-prebuilt/bin/phantomjs, count=1, browserName=phantomjs}]
at Object.checkLegacyResponse (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/error.js:505:15)
at parseHttpResponse (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
at Function.createSession (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/webdriver.js:777:24)
at createDriver (/builds/netaachen/operator-app/node_modules/selenium-webdriver/index.js:167:33)
at Builder.build (/builds/netaachen/operator-app/node_modules/selenium-webdriver/index.js:632:14)
at Hosted.getNewDriver (/builds/netaachen/operator-app/node_modules/protractor/lib/driverProviders/driverProvider.ts:60:29)
at Runner.createBrowser (/builds/netaachen/operator-app/node_modules/protractor/lib/runner.ts:225:39)
at q.then.then (/builds/netaachen/operator-app/node_modules/protractor/lib/runner.ts:391:27)
at _fulfilled (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:796:13)
at /builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:556:49
[09:53:28] E/launcher - Process exited with error code 199
ERROR: Build failed: exit code 1
答案 0 :(得分:2)
关键是在GitLab CI上使用Xvfb
。这会使显示屏旋转,因此--headless
Chrome可以运行规范。
我将更多信息和大量代码包含在How to run AngularJS end-to-end tests on GitLab CI的博文中。
答案 1 :(得分:1)
我已经使用过Gitlab CI但有Selenium经验。所以让我先描述一些重要的考虑因素:
PhantomJS
。它是一个实现Selenium协议的独立二进制文件。因此,为了使用PhantomJS - 只需使用PhantomJS启动容器。例如,我会使用这个:selenoid/phantomjs:2.1.1
(构建文件是here) - 它只运行phantomjs --webdriver=4444
。 PhantomJS默认侦听端口8910
,但由于上面的命令,我们仍然可以使用4444
。webdriver-manager
这是一个Javascript工具来下载Selenium服务器或webdriver二进制文件。使用PhantomJS不需要这样做。HUB_PORT_4444_TCP_ADDR
等环境变量的原因。所以我会将它们全部删除。说过,让我们尝试修改你的文件。
gitlab-ci.yml
变为:
image: node:7
services:
- selenoid/phantomjs:2.1.1
stages:
- test
test:
stage: test
before_script:
- npm install -s -g @angular/cli@1.0.6
- npm install -s
script:
- ./node_modules/.bin/protractor protractor.ci.conf.js
protractor.ci.conf.js
变为(seleniumAddress
中仅更改了容器名称):
/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': './node_modules/phantomjs-prebuilt/bin/phantomjs'
},
directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
seleniumAddress: 'http://selenoid__phantomjs:4444/wd/hub'
};
不确定什么是baseUrl
- 似乎是一些Protractor的东西,所以我认为不需要改变。如果有任何问题,请提出更多问题。