Chromedriver 手动工作,但在来自 Jenkins Slave 的 运行 时失败

Chromedriver works manually but fails when ran from Jenkins Slave

我有一个 Jenkins 从节点设置 LinuxMint。因此,我们可以在 Chrome 和 Firefox 中的 Linux 框上进行一些浏览器测试。

我安装了最新的 Chrome 驱动程序,测试可以 运行 它并且当我手动进入 /var/jenkins/workspace/<project name>/TestAutomation/SeleniumFramework 并执行我的 run npm <test name> 测试时启动 chromedriver 运行 成功。

当我进入 Jenkins 并且 运行 我的测试 chromedriver 失败并出现以下问题,我不知道该去哪里。:

Using ChromeDriver directly... [launcher] Running 1 instances of WebDriver /var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/atoms/error.js:108 var template = new Error(this.message); ^ UnknownError: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 3.19.0-32-generic x86_64) at new bot.Error (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/atoms/error.js:108:18) at Object.bot.response.checkResponse (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/atoms/response.js:109:9) at /var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:160:24 at promise.ControlFlow.runInFrame_ (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20) at goog.defineClass.notify (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25) at promise.Promise.notify_ (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12) at Array.forEach (native) at promise.Promise.notifyAll_ (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15) at goog.async.run.processWorkQueue (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/goog/async/run.js:130:15) at process._tickCallback (internal/process/next_tick.js:103:7) From: Task: WebDriver.createSession() at Function.webdriver.WebDriver.acquireSession_ (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22) at Function.webdriver.WebDriver.createSession (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30) at new Driver (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/selenium-webdriver/chrome.js:810:36) at DirectDriverProvider.getNewDriver (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/protractor/lib/driverProviders/direct.js:68:16) at Runner.createBrowser (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/protractor/lib/runner.js:182:37) at /var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/protractor/lib/runner.js:263:21 at _fulfilled (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/q/q.js:797:54) at self.promiseDispatch.done (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/q/q.js:826:30) at Promise.promise.promiseDispatch (/var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/q/q.js:759:13) at /var/jenkins/workspace/QA-E2E-Linux/TestAutomation/SeleniumFramework/node_modules/q/q.js:525:49 [launcher] Process exited with error code 1

第一个解:

你java8安装了吗?如果是,卸载并安装 java 7.

第二种解法:

将量角器降级到 v1.8.0

~

更多信息: https://github.com/angular/protractor/issues/1905

@edit

我发现了一个与你相似的主题,在 jenkins 中出现了同样的错误 - linux:

In you jenkins settings add a global property

key : DISPLAY
value:0:0

On your server start Xvfb in the background:

Xvfb :0 -ac -screen 0 1024x768x24 &

link: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9

所以我通过 SSH 从 Jenkins 主机连接到从机。这永远不会启动浏览器会话。我切换到 Java Web Start 选项,它启动浏览器就好了。