简体   繁体   中英

How do I use Xvfb to run protractor headless on Jenkins with chrome?

I am trying to run my protractor program from Jenkins , but since Jenkins doesn't have a display, I need to run chrome in headless mode. Since chrome doesn't have headless mode, I need to emulate a display using xvfb .

I followed a bunch of tutorials but when I run protractor, chrome crashes.

Here's what I have:

Build - Execute Shell (In Jenkins job)

#emulate display
echo "Starting xvfb on :99..."
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99

echo "Checking that xvfb started ok..."
xdpyinfo -display :99 >/dev/null 2>&1 && echo "xvfb is using :99" || echo "xvfb is not using :99, it's free."

#now start my program
xvfb-run -a --server-args='-screen 0, 1024x768x16' protractor conf.js

And here's my output:

+ echo Starting xvfb on :99...
Starting xvfb on :99...
+ export DISPLAY=:99
+ echo Checking that xvfb started ok...
Checking that xvfb started ok...
+ xdpyinfo -display :99
+ Xvfb -ac :99 -screen 0 1280x1024x16
+ echo xvfb is using :99
xvfb is using :99

[22:26:25] I/local - Starting selenium standalone server...
[22:26:25] I/launcher - Running 1 instances of WebDriver
[22:26:26] I/local - Selenium standalone server started at http://10.0.0.82:54385/wd/hub
[22:27:26] E/launcher - unknown error: Chrome failed to start: crashed
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-47-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.16 seconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ip-10-0-0-82', ip: '10.0.0.82', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
[22:27:26] E/launcher - WebDriverError: unknown error: Chrome failed to start: crashed
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-47-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.16 seconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ip-10-0-0-82', ip: '10.0.0.82', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at WebDriverError (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/error.js:27:5)
    at Object.checkLegacyResponse (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/error.js:639:15)
    at parseHttpResponse (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/http/index.js:538:13)
    at client_.send.then.response (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/http/index.js:472:11)
    at ManagedPromise.invokeCallback_ (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/promise.js:1379:14)
    at TaskQueue.execute_ (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/promise.js:2913:14)
    at TaskQueue.executeNext_ (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/promise.js:2896:21)
    at asyncRun (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/promise.js:2820:25)
    at /jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/lib/webdriver.js:329:24)
    at Builder.build (/jenkins/workspace/myjob/src/js/node_modules/selenium-webdriver/builder.js:458:24)
    at Local.DriverProvider.getNewDriver (/jenkins/workspace/myjob/src/js/node_modules/protractor/built/driverProviders/driverProvider.js:37:33)
    at Runner.createBrowser (/jenkins/workspace/myjob/src/js/node_modules/protractor/built/runner.js:198:43)
    at /jenkins/workspace/myjob/src/js/node_modules/protractor/built/runner.js:277:30
    at _fulfilled (/jenkins/workspace/myjob/src/js/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/jenkins/workspace/myjob/src/js/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/jenkins/workspace/myjob/src/js/node_modules/q/q.js:796:13)
    at /jenkins/workspace/myjob/src/js/node_modules/q/q.js:604:44
    at runSingle (/jenkins/workspace/myjob/src/js/node_modules/q/q.js:137:13)
[22:27:26] E/launcher - Process exited with error code 199

I keep getting Chrome failed to start: crashed with everything I tried... is this a problem with how I'm starting or configuring xvfb? Or is this a problem with my protractor code? The stacktrace isn't helping me at all xx

I would recommend using the Jenkins Xvfb Plugin . It works really well without having to mess too much with configurations.

To set up a job, just click on the xvfb option to run at the start of the job and shut down xvfb at the end of your job. Once you've set that, you can execute your Protractor commands without the xvfb stuff: protractor conf.js .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM