我正在尝试使用Jenkins,Selenium和Protractor构建我的测试环境。我决定使用selenium-plugin(selenium grid)在远程机器(节点)之间调度测试。到目前为止我所取得的成就是建立了硒中心与节点之间的连接。
Jenkins上安装的Node.js版本是5.12.0,Protractor是3.3.0。我还安装了npm chromedriver
并在protractor.config.js中设置了这个驱动程序的路径,如:
chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver'
节点正在运行selenium-standalone服务器,使用npm全局安装。
当我执行protractor.config.js文件时,出现以下错误:
protractor /u01/apps/jenkins/data/workspace/Servers/testApp/protractor.conf.js
[14:49:08] I/direct - Using ChromeDriver directly...
[14:49:08] I/launcher - Running 1 instances of WebDriver
/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329
return callbackFn(this.value_);
^
Error: Server terminated early with status 127
at Error (native)
at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/remote/index.js:210:20
at Promise.invokeCallback_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
at acquireSession (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
at Function.createSession (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
at Driver (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/chrome.js:778:38)
at Direct.getNewDriver (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/driverProviders/direct.js:65:26)
at Runner.createBrowser (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/runner.js:182:43)
at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/runner.js:255:30
at _fulfilled (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:796:13)
at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:556:49
[14:49:08] E/launcher - Process exited with error code 1
这是我的量角器配置文件:
exports.config = {
directConnect: true,
chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver',
framework: 'jasmine',
capabilities: {
'browserName': 'chrome',
shardTestFiles: true,
maxInstances: 3
},
specs: ['test/test_spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
},
seleniumAddress: 'http://HUB_IP:4444/wd/hub',
onPrepare: function() {
browser.driver.manage().window().maximize();
},
plugins: [{
package: 'protractor-console',
logLevels: ['severe', 'debug', 'info', 'warning']
}]
};
答案 0 :(得分:2)
你需要directConnect: false,
所以它会通过seleniumAddress: 'http://HUB_IP:4444/wd/hub',
使用selenium服务器,如果你是Jenkins,可能是无头模式,我建议你使用docker-selenium
启动本地网格
CONTAINER_ID="grid_$BUILD_NUMBER"
docker run -d --name=$CONTAINER_ID -v /dev/shm:/dev/shm elgalu/selenium
等待它开始
docker exec $CONTAINER_ID wait_all_done 40s
抓住IP
export HUB_IP=$(docker inspect -f='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID)
运行测试
protractor testApp/protractor.conf.js