Headless protractor tests don't plug on Xvfb

2019-09-14 23:50发布

问题:



I'm trying to run Protractor tests both in command line and with Jenkins. Both fail with the same error.

Command line

  • I opened a prompt and launched webdriver-manager start
  • In another prompt, I launched Xvfb :42 -ac -screen 0 1024x768x24 &
  • In a third one, I eventually launched protractor myconf.js

Jenkins

  • In my build, I checked "Start Xvfb before the build, and shut it down after.".
  • I run the tests in a shell script.

    sh 'sudo webdriver-manager clean'
    sh 'sudo webdriver-manager update'
    sh 'xvfb-run webdriver-manager start --seleniumPort 9094 &'
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'tests']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'myprettycredentials', url: 'myprettyproject.git']]])
    sh 'sudo sudo chmod -R a+rwx tests'
    sh 'sudo killall Xvfb'
    sh 'export DISPLAY=:43'
    sh 'sudo Xvfb :43 -ac -screen 0 1024x768x24 &'
    wrap([$class: 'Xvfb']) {
    sh 'sudo protractor tests/src/conf-demo.js --troubleshoot'
    }

In both cases, I get this error.

Failed: unknown error: an X display is required for keycode conversions,
consider using Xvfb

Why won't my tests plug on the Xvfb I started for them so zealously? Thanks for your help.

回答1:

Alright, I finally managed to run my Protractor tests headlessly using

xvfb-run -a webdriver-manager start --seleniumPort 9094 &
protractor myconf.js

Where -a chooses any free display, and & makes the task run in background.



回答2:

Great to hear you resolve your issue.

Another alternative would be to create a gulp task and use the gulp-angular-protractor extension. I think is easier to configure and run.

And install the xvfb plugin to use it on the configuration on your job.

Good Luck !