为什么 URL 不能在 FirefoxDriver 中使用 Selenium?

Why URL not working with Selenium in FirefoxDriver?

我有一个 Selenium、TestNG 和 maven 应用程序。

如果我 运行 mvn intergration-test Firefox 浏览器打开但 URL 不工作。

在控制台中也出现以下错误

Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055

我的pom.xml

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

<groupId>com.selenium</groupId>
<artifactId>Selenium</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Selenium</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.selenium>2.53.1</version.selenium>
    <version.testng>6.9.10</version.testng>
    <version.maven.compiler.plugin>2.3.2</version.maven.compiler.plugin>
    <version.java.source>1.8</version.java.source>
    <version.java.target>1.8</version.java.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${version.testng}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <!-- <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server-standalone</artifactId> 
            <version>${version.selenium}</version> <scope>test</scope>  -->
         <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version> 
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${version.maven.compiler.plugin}</version>
            <configuration>
                <source>${version.java.source}</source>
                <target>${version.java.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xms128m -Xmx256m -XX:PermSize=128m -XX:MaxPermSize=256m</argLine>
                <parallel>true</parallel>
                <suiteXmlFiles>
                    <suiteXmlFile>src/main/java/com/selenium/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <!-- Skip the normal tests, we'll run them in the integration-test phase -->
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当浏览器版本与您的驱动程序版本不兼容时,我通常会看到这种行为,从您的 pom 我看到您使用的是 selenium v​​er 2.25,这有点旧,我认为只支持 FF 14。请确认您使用的是正确版本的 Firefox。如果您在安装旧版本的 firefox 时需要帮助,请参阅:

https://support.mozilla.org/en-US/kb/install-older-version-of-firefox