Is it possible to start a Selenium server inside Travis?

无人久伴 提交于 2020-01-01 12:36:28

问题


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.

回答1:


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'
    },
}



回答2:


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:

  • Starting a Selenium Server inside TravisCI
  • GUI and Headless Browser Testing


来源:https://stackoverflow.com/questions/37699036/is-it-possible-to-start-a-selenium-server-inside-travis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!