gpt4 book ai didi

node.js - 使用 Jenkins、selenium-grid 和 Protractor 进行 e2e 测试

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:44 25 4
gpt4 key购买 nike

我正在尝试使用 Jenkins、Selenium 和 Protractor 构建我的测试环境。我决定使用 selenium-plugin(selenium grid)在远程机器( Node )之间调度测试。到目前为止我所取得的成就是在 Selenium 集线器和 Node 之间建立连接。

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'

Node 正在运行 selenium 独立服务器,通过 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

这是我的 Protractor 配置文件:

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']
}]
};

最佳答案

您需要 directConnect: false, 这样它将通过 seleniumAddress: 'http://HUB_IP:4444/wd/hub', 使用 selenium 服务器,并且考虑到您在 Jenkins 上,可能处于 headless 模式,我建议您使用 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

关于node.js - 使用 Jenkins、selenium-grid 和 Protractor 进行 e2e 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com