【问题标题】:Selenium tests won't run in jenkins using FirefoxDriver, runs fine on local desktopSelenium 测试不会在使用 FirefoxDriver 的 jenkins 中运行,在本地桌面上运行良好
【发布时间】:2015-07-15 15:37:06
【问题描述】:

我正在尝试让我的硒测试在 Jenkins 中运行,但面临以下问题。使用 maven test 或 intellij 运行时,测试在我的本地计算机上运行良好。

火狐 39 x64
硒 2.46.0
SeleniumHQ 插件(自动更新,所以应该是最新版本)

据此,Xvfb 服务器应该正在运行

Xvfb starting$ Xvfb :1 -screen 0 1024x758x16 -fbdir /data/jenkins/xvfb-64-6044594236651529452.fbdir

问题出在哪里?经过 2 天的互联网搜索并尝试了我发现的所有内容后,我无法弄清楚。

来源:

public void setUp() throws Exception {
        String Xport = System.getProperty("lmportal.xvfb.id", ":1");
        FirefoxBinary firefoxBinary = new FirefoxBinary();
        firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
        driver = new FirefoxDriver(firefoxBinary, null);
        baseUrl = BASE_URL;
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

错误:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    1436973591335   DeferredSave.extensions.json    DEBUG   Save changes
    1436973591336   addons.xpi  DEBUG   Updating XPIState for {"id":"fxdriver@googlecode.com","syncGUID":"NERSGr4g-th8","location":"app-profile","version":"2.46.0","type":"extension","internalName":null,"updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Firefox WebDriver","description":"WebDriver implementation for Firefox","creator":"Simon Stewart","homepageURL":null},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"/tmp/anonymous134216584359310857webdriver-profile/extensions/fxdriver@googlecode.com","installDate":1436973590000,"updateDate":1436973590000,"applyBackgroundUpdates":1,"bootstrap":false,"size":8440790,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true,"hasBinaryComponents":true,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"3.0","maxVersion":"66.*"}],"targetPlatforms":[{"os":"Darwin","abi":null},{"os":"SunOS","abi":null},{"os":"FreeBSD","abi":null},{"os":"OpenBSD","abi":null},{"os":"WINNT","abi":"x86-msvc"},{"os":"Linux","abi":null}],"multiprocessCompatible":false}
    1436973591336   addons.xpi  DEBUG   getModTime: Recursive scan of fxdriver@googlecode.com
    1436973591338   addons.xpi  DEBUG   New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
    1436973591340   addons.xpi-utils    DEBUG   Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
    1436973591340   DeferredSave.extensions.json    DEBUG   Save changes
    1436973591340   DeferredSave.extensions.json    DEBUG   Save changes
    1436973591340   addons.xpi  DEBUG   Updating XPIState for {"id":"{972ce4c6-7e08-4474-a285-3208198ce6fd}","syncGUID":"oj50TlNJya_g","location":"app-global","version":"39.0","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"/data/jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/Firefox/firefox/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}","installDate":1435710843000,"updateDate":1435710843000,"applyBackgroundUpdates":1,"skinnable":true,"size":3169,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"39.0","maxVersion":"39.0"}],"targetPlatforms":[]}
    1436973591340   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
    1436973591341   addons.xpi  DEBUG   Updating database with changes to installed add-ons
    1436973591341   addons.xpi-utils    DEBUG   Updating add-on states
    1436973591341   addons.xpi-utils    DEBUG   Writing add-ons list
    1436973591345   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
    1436973591346   addons.manager  DEBUG   Provider finished startup: XPIProvider
    1436973591346   addons.manager  DEBUG   Starting provider: LightweightThemeManager
    1436973591346   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
    1436973591346   addons.manager  DEBUG   Provider finished startup: LightweightThemeManager
    1436973591346   addons.manager  DEBUG   Starting provider: GMPProvider
    1436973591350   addons.manager  DEBUG   Registering shutdown blocker for GMPProvider
    1436973591351   addons.manager  DEBUG   Provider finished startup: GMPProvider
    1436973591351   addons.manager  DEBUG   Starting provider: PluginProvider
    1436973591351   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
    1436973591351   addons.manager  DEBUG   Provider finished startup: PluginProvider
    1436973591352   addons.manager  DEBUG   Completed startup sequence
    1436973591586   DeferredSave.extensions.json    DEBUG   Starting timer

        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:120)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:275)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:220)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:215)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
        at cz.bsc.g6.mbs.pda.selenium.ide.Base.setUp(Base.java:52)
        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:606)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
        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:606)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

【问题讨论】:

    标签: selenium jenkins selenium-firefoxdriver


    【解决方案1】:

    您是否设置了 DISPLAY 环境变量?为了在无头模式下执行测试,需要设置此项。

    我们使用 Xvnc Jenkins 插件在作业设置中为变量分配一个随机数:

    https://wiki.jenkins-ci.org/display/JENKINS/Xvnc+Plugin

    这也是使用 Jenkins 启动和运行无头测试的非常有用的指南:

    http://blog.dahanne.net/2011/07/18/run-ui-tests-on-a-headless-jenkins-hudson-continuous-integration-server-running-ubuntu/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 2019-01-14
      • 1970-01-01
      • 2016-10-20
      • 2016-11-29
      • 1970-01-01
      • 2013-01-31
      相关资源
      最近更新 更多