无法在Maven中使用Selenium连接二进制FirefoxBinary

kir*_*hel 33 java junit selenium maven selenium-webdriver

我正在运行一些Selenium-Tests.当我直接从Eclipse启动它们时,一切正常.但是当我通过Maven启动它们时会发生以下异常:

org.openqa.selenium.WebDriverException(Failed to connect to binary FirefoxBinary(C:\winapp\Firefox\firefox.exe) on port 7055; process output follows: 
null
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_35'
Driver info: driver.version: FirefoxDriver)
Run Code Online (Sandbox Code Playgroud)

我使用的是Firefox 10.0.10 ESR.我也尝试过Selenium 2.25.0.

这是我最新版本的pom.xml:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.26.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.26.0</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.jdom</groupId>
        <artifactId>jdom2</artifactId>
        <version>2.0.3</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

如果我能为您提供更多信息,请告诉我们.

编辑:更新的pom.xml

edit2:最让我感到奇怪的是,我可以在没有问题的情况下运行eclipse中的测试.它们只是发生,如果我称之为"mvn install"

小智 29

当我遇到这个错误时,它通常是两件事之一.

Selenium版本不支持浏览 器版本从Eclipse vs Maven运行时,检查Selenium /浏览器版本是否相同.仔细检查Eclipse和Maven配置为使用相同的Selenium版本.当我的浏览器自动更新时,我发生这种情况,所以我在浏览器中将其关闭.

Selenium测试在无头模式下运行, 如果您在与Eclipse相同的机器上手动执行mvn,则不太可能.在我的Jenkins服务器上通过Maven运行Selenium时,我发生了这种情况.Jenkins服务器以无头模式运行.我花了很多时间来弄清楚无头的东西,想想我在Linux中设置了一个DISPLAY env变量.

  • 设置DISPLAY env变量后,问题是否已解决?我想我遇到了同样的问题. (2认同)

kir*_*hel 5

我想出了问题所在.

我加载了一些扩展,以添加到我用来实例化FireFoxDriver的FirefoxProfile中.这些插件位于Java/main/resources下.在Eclipse中一切正常,但我无法通过Maven访问这些插件.将这些文件复制到临时文件夹后,从那里加载它们甚至可以从Maven中运行.

谢谢你的帮助