是否可以在Travis中启动Selenium服务器?

时间:2016-06-08 09:49:47

标签: selenium travis-ci

我想在Travis中运行一个完整的Selenium测试,但我似乎无法启动服务器。

我的Travis YAML文件

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

运行npm test时,结果为:

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 个答案:

答案 0 :(得分:1)

是的!我刚刚做了。

以下是我的package.json依赖项:

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

这是我的.travis.yml文件:

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

这是我的wdio.conf.js文件的摘录:

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

答案 1 :(得分:1)

我在Travis CI的e2e测试中需要3件事来启动Selenium服务器:

  1. sudo required
  2. chrome addons
  3. xvfb-run(travis-ci上没有屏幕)
  4. 这是我的.travis.yml(见第1,5,6和9行)

    参考: