在jenkins构建下以无头模式运行cucumber-jvm selenium测试用例时出错

背景

我有一个在spring-boot和maven中设计的项目。 它包含了yellow-jvm selenium测试用例,我希望在jenkins构建中以无头模式运行。 为此,我在jenkins构建机器上安装了XVfb ,并确保Xvfb正在运行。

 $ps -ef | grep Xvfb root 3804 1 0 Sep29 ? 00:52:41 Xvfb -ac :99 -screen 0 1280x1024x16 

接下来,我还在构建开始时导出DISPLAY变量,如下所示,

 export DISPLAY=:99 

错误

测试无法执行以下stackstrace

 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: Error: no display specified Error: no display specified at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118) at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:114) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:191) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:186) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:182) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:99) 

的pom.xml

   4.0.0 org.abc ABC ABC war  org.springframework.boot spring-boot-starter-parent 1.1.7.RELEASE      openqa OpenQA Repository http://nexus.openqa.org/content/repositories/releases/  false   true      codehaus snapshot repository http://snapshots.repository.codehaus.org/  true   <!--    -->     org.springframework.boot spring-boot-starter-actuator   org.springframework.boot spring-boot-starter-tomcat   org.springframework.boot spring-boot-starter-logging     org.springframework.boot spring-boot-starter-jetty   org.springframework.boot spring-boot-starter-logging     org.springframework.boot spring-boot-starter-web   org.springframework.boot spring-boot-starter-logging     org.springframework spring-context-support   commons-logging commons-logging      org.springframework.boot spring-boot-starter-security   commons-logging commons-logging      org.springframework.security spring-security-ldap   org.springframework.ldap spring-ldap-core 2.0.2.RELEASE   LdapSDK LdapSDK 1.0 provided    opentoken-adapter opentoken-adapter 2.5.1 provided    org.springframework.boot spring-boot-starter-test test   org.mockito mockito-all 1.9.5 test   info.cukes cucumber-spring 1.1.6 test   info.cukes cucumber-junit 1.1.6 test   org.seleniumhq.selenium selenium-java 2.44.0 test   org.seleniumhq.selenium selenium-firefox-driver 2.44.0 test   com.codeborne phantomjsdriver 1.2.1    ch.qos.logback logback-classic   org.slf4j jcl-over-slf4j    javax.mail mail 1.4.7    com.amazonaws aws-java-sdk 1.8.11    org.apache.velocity velocity provided    commons-io commons-io 2.4   commons-collections commons-collections     commons-logging commons-logging 1.2 provided   commons-lang commons-lang 2.6 provided   com.belerweb qq-connect 1.0.2   org.subethamail subethasmtp 3.1.7 test   org.apache.ant ant 1.9.3   commons-codec commons-codec 1.6   com.jayway.jsonpath json-path test   com.jayway.jsonpath json-path-assert 1.2.0 test   net.sf.json-lib json-lib 2.4 jdk15 test    src/test/ui target/integrationtest-classes 8000 UTF-8 org.healthfidelity.hfiam.Application 1.6     org.codehaus.mojo build-helper-maven-plugin   add-test-source pre-integration-test  add-test-source    src/test/ui       org.apache.maven.plugins maven-surefire-plugin 2.18   **/IT*.java     org.apache.maven.plugins maven-failsafe-plugin 2.18    integration-test verify      org.mortbay.jetty jetty-maven-plugin 8.1.16.v20140903  ${basedir}/target/HFIam.war 10 foo 1234 true true  /HFIam    3600000 ${jetty.port}      start-jetty pre-integration-test  run-war    stop-jetty post-integration-test  stop      org.codehaus.mojo selenium-maven-plugin    

作为决议,

  1. 我在xvfb上安装了xvfb插件。
  2. Build Environment部分,勾选选项在构建 Start Xvfb before the build, and shut it down after.