Since documentation on GitLab CI configuration and Selenium is generally poor, I'm asking for help.
Configuration as by interest point:
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/[email protected]
- 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'
};
With the above configuration, GitLab fails with:
$ ./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
The key is to use Xvfb
on GitLab CI. That spins up the display so --headless
Chrome can run the specs.
I wrapped more info and chunks of code into the blog post of How to run AngularJS end-to-end tests on GitLab CI.
I have neved used Gitlab CI but have Selenium experience. So let me first describe some important considerations:
PhantomJS
. It is a standalone binary implementing itself Selenium protocol. So in order to work with PhantomJS - just start container with PhantomJS. For example I would use this one: selenoid/phantomjs:2.1.1
(build file is here) - it just runs phantomjs --webdriver=4444
. PhantomJS by default listens on port 8910
but because of command above we can still use 4444
.webdriver-manager
which is a Javascript tool to download Selenium server or webdriver binaries. This is not needed to work with PhantomJS.HUB_PORT_4444_TCP_ADDR
were added. So I would remove them all.Having said that let's try to modify your files.
gitlab-ci.yml
becomes:
image: node:7
services:
- selenoid/phantomjs:2.1.1
stages:
- test
test:
stage: test
before_script:
- npm install -s -g @angular/[email protected]
- npm install -s
script:
- ./node_modules/.bin/protractor protractor.ci.conf.js
protractor.ci.conf.js
becomes (only changed container name in 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'
};
Not sure what is baseUrl
- seems to be some Protractor stuff, so I think don't need to change. Please ask more questions if any.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With