4
votes

I want to run a complete Selenium test within Travis, but I seem unable to get the server started.

My Travis YAML file

language: node_js

node_js:
  - "6.2"

before_script:
  - npm install selenium-standalone@latest -g
  - selenium-standalone install
  - npm install -g gulp
  - nohup selenium-standalone start > selenium.txt 2>&1 </dev/null &

script:
  - npm test
  - gulp

When npm test runs, the result is:

Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:4444
    at Object.exports._errnoException (util.js:1007:11)
    at exports._exceptionWithHostPort (util.js:1030:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
Connection refused! Is selenium server started?
npm ERR! Test failed.  See above for more details.
2
are you trying to run it on local? where is the server started? - Naman
Hi @nullpointer, nohup selenium-standalone start starts the server in the Travis container. - Bob van Luijt

2 Answers

2
votes

I needed 3 things to start Selenium server inside my e2e tests on Travis CI:

  1. sudo required
  2. chrome addons
  3. xvfb-run (there is no screen on travis-ci)

here is my .travis.yml (See line 1, 5-6 and 9)

refs:

1
votes

It is! I just did.

Here are my package.json dependencies:

"wdio-mocha-framework": "^0.5.10",
"wdio-selenium-standalone-service": "0.0.9",
"wdio-spec-reporter": "^0.1.0",
"webdriverio": "^4.8.0"

Here's my .travis.yml file:

sudo: required  
dist: trusty 
language: node_js
node_js:
  - "4.4"
env:
  global:
    - CXX=g++-4.8
    - DISPLAY=:99.0
    - CHROME_BIN=/usr/bin/google-chrome
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-4.8      
before_script:
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 # give xvfb some time to start
  - sudo apt-get update
  - sudo apt-get install -y libappindicator1 fonts-liberation
  - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  - sudo dpkg -i google-chrome*.deb
  - npm install --dev
  - npm run run & # to run my web server in the background
  - sleep 5 # give web server some time to start

And here's an extract of my wdio.conf.js file:

exports.config = {
    capabilities: [{
        maxInstances: 1,
        browserName: 'chrome'
    }],
    services: ['selenium-standalone'],
    framework: 'mocha',
    reporters: ['spec'],
    mochaOpts: {
        ui: 'bdd'
    },
}