Jenkins Selenium上的Firefox错误:“错误:无法打开显示”

时间:2016-01-07 10:41:37

标签: java selenium jenkins selenium-webdriver xvfb

我正在尝试使用Selenium在Jenkins上运行一个测试用例,但是我得到了一个“无法打开显示”(我已经尝试了显示“:1”和“:99”)。

一些信息:

  • Selenium v​​ersion 2.35.0
  • JDK 1.6.0_25
  • 我在Debian环境中运行
  • 我安装了Xvfb
  • DISPLAY在代码中声明(见下文)和jenkins / configure全局属性(name = DISPLAY,value =:99(或:1))

我的POM:

<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.squashtest.jenkins</groupId>
    <artifactId>my.squash.ta.project</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>

    <!-- Properties definition -->
    <properties>
        <!-- Squash-TA framework version used by the project -->
        <ta.framework.version>1.7.1-RELEASE</ta.framework.version>
        <!-- Log configuration file -->
        <logConfFile>src/log4j.properties</logConfFile>
    </properties>

    <build>
        <plugins>
            <!-- Configuration of the Squash TA framework used by the project -->
            <plugin>
                <groupId>org.squashtest.ta</groupId>
                <artifactId>squash-ta-maven-plugin</artifactId>
                <version>${ta.framework.version}</version>

                <dependencies>
                    <dependency>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-java</artifactId>
                        <version>2.35.0</version>
                    </dependency>  
                     <dependency>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-firefox-driver</artifactId>
                        <version>2.35.0</version>
                    </dependency>
                     <dependency>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-server</artifactId>
                        <version>2.35.0</version>
                     </dependency>  
                </dependencies>

                <!-- Under here is the Squash TA framework default configuration -->
                <configuration>

                    <!-- Uncomment the line below in order to the build finish in success even if a test failed -->
                    <!-- <alwaysSuccess>true</alwaysSuccess> -->

                    <!-- Define a log configuration file (at log4j format) to override the one defined internally -->
                    <!-- If the given file can't be found the engine switch to the internal configuration-->
                    <logConfiguration>${logConfFile}</logConfiguration>

                    <!-- Define exporters -->
                    <exporters>
                        <surefire>
                            <jenkinsAttachmentMode>${ta.jenkins.attachment.mode}</jenkinsAttachmentMode>
                        </surefire>
                        <html/>
                    </exporters>

                    <!-- Define configurers -->
                    <configurers>
                        <tmCallBack>
                            <endpointURL>${status.update.events.url}</endpointURL>
                            <executionExternalId>${squash.ta.external.id}</executionExternalId>
                            <jobName>${jobname}</jobName>
                            <hostName>${hostname}</hostName>
                            <endpointLoginConfFile>${squash.ta.conf.file}</endpointLoginConfFile>
                        </tmCallBack>
                    </configurers>
                </configuration>

                <!-- Bind the Squash TA "run" goal to the maven integration-test phase and reuse the default configuration -->
                <executions>
                    <execution>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <!-- Squash TA maven repository -->
    <repositories>
        <repository>
            <id>org.squashtest.ta.release</id>
            <name>squashtest test automation - releases</name>
            <url>http://repo.squashtest.org/maven2/releases</url>
        </repository>
    </repositories>

    <!-- Squash TA maven plugin repository -->
    <pluginRepositories>
        <pluginRepository>
            <id>org.squashtest.plugins.release</id>
            <name>squashtest.org</name>
            <url>http://repo.squashtest.org/maven2/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

</project>

我的代码:

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import java.io.File;
import org.openqa.selenium.support.ui.Select;

public class ConnexionInterfaceFortress {

String baseUrl = "http://foobar.com";
WebDriver driver = null;
StringBuffer verificationErrors = new StringBuffer();
boolean acceptNextAlert = true;
FirefoxBinary binary = new FirefoxBinary(new File("/usr/bin/firefox"));
FirefoxProfile profile = new FirefoxProfile();

  @Before
  public void setUp() throws Exception {
  }

  @Test
  public void testConnexion() throws Exception {
try{
        binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":99"));
        profile.setEnableNativeEvents(true);
        driver = new FirefoxDriver(binary, profile);
        } catch (Error e) {
            System.out.println("Creation du navigateur impossible");
        }
    driver.manage().window().maximize();      
    driver.get(baseUrl); 
 }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alert.getText();
    } finally {
      acceptNextAlert = true;
    }
  }
}

我的完整日志:

Started by user tmserver
Building in workspace /usr/local/bin/squashta/execution_home/jobs/Connexion 2/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@gitlab.rvip.fr:qa/QAJenkinsTest.git # timeout=10
Fetching upstream changes from git@gitlab.rvip.fr:qa/QAJenkinsTest.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress git@gitlab.rvip.fr:qa/QAJenkinsTest.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 05b328fa1a5b07a9c225eee58683e6d19ef98fa1 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 05b328fa1a5b07a9c225eee58683e6d19ef98fa1
 > git rev-list 00124836ba6caebc7e9ffbd234b2fa01488c10b9 # timeout=10
provisoning config files...
copy managed file [conf.properties] to file:/usr/local/bin/squashta/execution_home/taLinkConf.properties
Copying file to testsuite.json
Parsing POMs
using global settings config with name TaGlobalSettings
Replacing all maven server entries not found in credentials list is null
[workspace] $ /usr/local/bin/squashta/openjdk1.6.0_25-unix-i586/bin/java -Xms512m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=512m -cp /usr/local/bin/squashta/execution_home/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.4.jar:/usr/local/bin/squashta/apache-maven-3.0.4/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /usr/local/bin/squashta/apache-maven-3.0.4 /usr/local/bin/squashta/apache-tomcat-7.0.54/webapps/jenkins/WEB-INF/lib/remoting-2.33.jar /usr/local/bin/squashta/execution_home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.4.jar /usr/local/bin/squashta/execution_home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.4.jar 56944
<===[JENKINS REMOTING CAPACITY]===>channel started
using global settings config with name TaGlobalSettings
Replacing all maven server entries not found in credentials list is null
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
Executing Maven:  -B -f /usr/local/bin/squashta/execution_home/jobs/Connexion 2/workspace/pom.xml -gs /usr/local/bin/squashta/apache-tomcat-7.0.54/temp/global-settings7531672306724044985.xml -Dta.test.suite=ConnexionInterfaceFortress.ta -Dstatus.update.events.url=file://dev/null -Dsquash.ta.external.id= -Djobname=Connexion 2 -Dhostname=AWS-RND-TEST-PR -Dsquash.ta.conf.file=/usr/local/bin/squashta/execution_home/taLinkConf.properties -Dta.tmcallback.reportbaseurl=http://squashta.rvip.fr:9080/jenkins/job -Dta.tmcallback.jobexecutionid=46 -Dta.tmcallback.reportname=Squash_TA_HTML_Report -Dta.delete.json.file=true org.squashtest.ta::squash-ta-maven-plugin::run
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my.squash.ta.project 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- squash-ta-maven-plugin:1.7.1-RELEASE:run (default-cli) @ my.squash.ta.project ---
[INFO] Loading external logging configuration: /usr/local/bin/squashta/execution_home/jobs/Connexion 2/workspace/src/log4j.properties
[INFO] Squash TA : compiling tests...
[INFO] Squash TA : initializing context...
[INFO] org.squashtest.ta.backbone.init.ComponentPackagesEnumerator - Listing sqhashTA engine component packages
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.enginecore
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.commons-component
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.filechecker
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.sahi
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.selenium
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.local.process
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.soapui
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.ftp
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.db
[INFO] org.squashtest.ta.backbone.init.ComponentManifestParser - Loading plugin configuration for: org.squashtest.ta.plugin.ssh
[WARN] org.squashtest.ta.link.SquashTMCallbackEventConfigurer - The endpoint URL is set to its default value: "file://dev/null", so the call back is not activated
[INFO] Squash TA : testing...
[INFO] org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl - Beginning execution of ecosystem tests
[INFO] org.squashtest.ta.backbone.engine.impl.TestRunnerImpl - Beginning execution of test setup.ta
[INFO] org.squashtest.ta.backbone.engine.impl.TestRunnerImpl - Beginning execution of test ConnexionInterfaceFortress.ta
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: cannot open display: :99
Error: cannot open display: :99

    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:251)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:195)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at ConnexionInterfaceFortress.testConnexion(ConnexionInterfaceFortress.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
    at org.squashtest.ta.plugin.selenium.library.StandardJUnitExecutor.apply(StandardJUnitExecutor.java:74)
    at org.squashtest.ta.plugin.selenium.commands.ExecuteJavaSeleniumTwoCommand.apply(ExecuteJavaSeleniumTwoCommand.java:80)
    at org.squashtest.ta.plugin.selenium.commands.ExecuteJavaSeleniumTwoCommand.apply(ExecuteJavaSeleniumTwoCommand.java:1)
    at org.squashtest.ta.backbone.engine.wrapper.CommandHandler.apply(CommandHandler.java:132)
    at org.squashtest.ta.backbone.engine.instructionrunner.DefaultExecuteCommandRunner.doRun(DefaultExecuteCommandRunner.java:79)
    at org.squashtest.ta.backbone.engine.instructionrunner.AbstractDefaultInstructionRunner.run(AbstractDefaultInstructionRunner.java:69)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstruction(TestRunnerImpl.java:190)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstructionList(TestRunnerImpl.java:139)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runMetaInstruction(TestRunnerImpl.java:162)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstructionList(TestRunnerImpl.java:137)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runPhase(TestRunnerImpl.java:127)
    at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runTest(TestRunnerImpl.java:108)
    at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.runAllTests(EcosystemRunnerImpl.java:185)
    at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.run(EcosystemRunnerImpl.java:103)
    at org.squashtest.ta.backbone.engine.impl.SuiteRunnerImpl.execute(SuiteRunnerImpl.java:68)
    at org.squashtest.ta.backbone.engine.impl.EngineImpl.execute(EngineImpl.java:63)
    at org.squashtest.ta.maven.SquashTAMojo.executeImpl(SquashTAMojo.java:204)
    at org.squashtest.ta.maven.AbstractSquashTaMojo.execute(AbstractSquashTaMojo.java:209)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
    at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:178)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:134)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:69)
    at hudson.remoting.UserRequest.perform(UserRequest.java:118)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:328)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
[ERROR] org.squashtest.ta.backbone.engine.impl.TestRunnerImpl - The execution failed in the TEST phase of the TA script 'ConnexionInterfaceFortress.ta' with the message: 'Selenium test failed. Following are the name of the tests that failed:
testConnexion(ConnexionInterfaceFortress)
testConnexion(ConnexionInterfaceFortress)
'.
[INFO] org.squashtest.ta.backbone.engine.impl.TestRunnerImpl - Beginning execution of test teardown.ta
[INFO] Exporting results
[INFO] Cleaning resources
[INFO] Squash TA : build complete.
[INFO] org.squashtest.ta.core.tools.io.TempFileUtils - All the files from /tmp/Squash_TA were properly deleted.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 53.303s
[INFO] Finished at: Thu Jan 07 11:08:27 CET 2016
[INFO] Final Memory: 24M/490M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving disabled
Waiting for Jenkins to finish collecting data[ERROR] Failed to execute goal org.squashtest.ta:squash-ta-maven-plugin:1.7.1-RELEASE:run (default-cli) on project my.squash.ta.project: Build failure : there are tests failures
[ERROR] Test statistics : 1 test runs, 0 passed, 1 tests didn't pass
[ERROR] Tests failed / crashed :
[ERROR] -----------
[ERROR] tests:
[ERROR] ==> ConnexionInterfaceFortress.ta
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

channel stopped
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at BUILD level /usr/local/bin/squashta/execution_home/jobs/Connexion 2/workspace/target/squashTA/html-reports to /usr/local/bin/squashta/execution_home/jobs/Connexion 2/builds/2016-01-07_11-07-26/htmlreports/Squash_TA_HTML_Report
[htmlpublisher] Archiving at PROJECT level /usr/local/bin/squashta/execution_home/jobs/Connexion 2/workspace/target/squashTA/test-tree to /usr/local/bin/squashta/execution_home/jobs/Connexion 2/htmlreports/Test_list
Finished: FAILURE

有谁知道我做错了什么?

提前谢谢。

2 个答案:

答案 0 :(得分:1)

首先,通过在本地测试来修复Firefox版本和selenium版本匹配。如果您正在通过Jenkins运行作业,并且在日志中出现错误:

Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: Error: cannot open display: :0

要解决此问题,请查看以下步骤:

  1. 只有在Xvfb运行时才会启动Firefox,请记住Xvfb在虚拟内存中执行所有图形操作而不显示任何屏幕输出。运行Xvfb,如下所示。 例如:Xvfb :15 -screen 0 1024x768x16所以首先检查一下,通过将ps -ef添加到作业的预执行(shell执行)中,可以将此检查包含到作业中。

  2. 即使您明确定义了DISPLAY值但仍然存在错误,那么最好的方法是在Jenkin作业本身注入环境值。在构建环境&gt;&gt;下注入env变量&gt;&gt;属性内容&gt;&gt; DISPLAY =:15 (您可以根据自己设置显示,同样应该在xvfb正在运行)

  3. 运行你的工作,应该已经修好了。

答案 1 :(得分:0)

事实证明,Jenkins用户只是一个服务帐户,它无法访问任何X服务器会话,因此无法打开浏览器来完成测试。

除非您在Xvfb plugin的帮助下以无头模式运行,或通过Xvnc plugin给出的虚拟显示查看输出,否则目前似乎没有更好的方法来实现硒测试在詹金斯建立。

您可能希望详细了解现有问题here