【问题标题】:Is it possible to start a Selenium server inside Travis?是否可以在 Travis 中启动 Selenium 服务器?
【发布时间】:2023-03-12 15:25:01
【问题描述】:

我想在 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.

【问题讨论】:

  • 你想在本地运行它吗?服务器在哪里启动?
  • 嗨@nullpointer,nohup selenium-standalone start 在 Travis 容器中启动服务器。

标签: selenium travis-ci


【解决方案1】:

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

  1. 需要sudo
  2. chrome 插件
  3. xvfb-run(travis-ci 上没有屏幕)

这是我的.travis.yml(见第 1、5-6 和 9 行)

参考:

【讨论】:

    【解决方案2】:

    是的!我刚做了。

    这是我的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'
        },
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多