如何使用无头浏览器在Jenkins中运行量角器测试用例?

时间:2016-08-22 13:29:11

标签: jenkins protractor headless-browser

我使用过phantomjs但幻像js的兼容性与量角器有关。虽然在chrome和firefox浏览器中我能找到元素,但在phantomjs中找不到相同的定位器。

2 个答案:

答案 0 :(得分:3)

如果您使用的是Linux操作系统,则可以使用xvfb以无头模式启动Chrome浏览器。

要安装xvfb,请在终端

中运行以下命令
sudo apt-get update

sudo apt-get install -y xvfb

安装xfvb后,可以使用以下命令

运行量角器脚本
xvfb-run protractor configuration.js

上述命令将以无头模式启动Chrome浏览器,并将执行configuration.js文件中提到的所有规范。

答案 1 :(得分:1)

我的Package.JSON:

{
  "name": "Protractor-Test",
  "version": "1.0.0",
  "description": "UI Automation of Media WorkFlow by Protractor",
  "main": "conf.js",
  "author": "Subhasish Mishra",
  "license": "ISC",
  "repository": {
    "type": "git",
    "url": ""
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "jasmine-core": "~2.4.1",
    "jasmine-expect": "~2.0.1",
    "jasmine-reporters": "~2.1.1",
    "karma-junit-reporter": "^0.2.2",
    "protractor": "~3.1.1",
    "protractor-console": "~2.0.1",
    "protractor-html-screenshot-reporter": "0.0.21",
    "protractor-jasmine2-html-reporter": "0.0.6",
    "selenium-webdriver": "~2.53.2",
    "webdriver-manager":"10.2.1"
  }
}

My conf.js file

我的script.sh从Jenkins触发量角器测试

script.sh个文件 enter image description here

从Jenkins构建后出错

[launcher] Process exited with error code 1

/var/lib/jenkins/workspace/media-msod-automationtest-master/node_modules/protractor/node_modules/q/q.js:155
                throw e;
                      ^
SyntaxError: Unexpected token )
    at goog.loadModuleFromSource_ (/var/lib/jenkins/workspace/media-msod-automationtest-master/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1123:19)
    at Object.goog.loadModule (/var/lib/jenkins/workspace/media-msod-automationtest-master/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1085:46)
    at /var/lib/jenkins/workspace/media-msod-a