Java Selenium Maven安装程序-一个空罐

Java Selenium Maven安装程序-一个空罐,java,eclipse,maven,selenium,Java,Eclipse,Maven,Selenium,我正在尝试使用以下推荐的Maven指令设置Java Selenium测试: 在这里: 我已经安装了maven并正在工作 我复制了示例pom.xml,只更改了项目名称 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta

我正在尝试使用以下推荐的Maven指令设置Java Selenium测试:

在这里:

我已经安装了maven并正在工作

我复制了示例pom.xml,只更改了项目名称

<?xml version="1.0" encoding="UTF-8"?>
<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>SeleniumTest</groupId>
        <artifactId>SeleniumTest</artifactId>
        <version>1.0</version>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.44.0</version>
            </dependency>
            <dependency>
                <groupId>com.opera</groupId>
                <artifactId>operadriver</artifactId>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.opera</groupId>
                    <artifactId>operadriver</artifactId>
                    <version>1.5</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.seleniumhq.selenium</groupId>
                            <artifactId>selenium-remote-driver</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </dependencyManagement>
</project>
运行时没有任何错误。将创建目标目录,其中包含SeleniumTest-1.0.jar和maven archiver目录。问题是我的Eclipse项目无法解析Selenium类。我复制了示例Java驱动程序类,根据我的项目布局修改了导入:

import Selenium.*;
import Selenium.target.*;

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });

        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());

        //Close the browser
        driver.quit();
    }
}
都失败了

我查看了Maven下载的jar,SeleniumTest-1.0.jar,它实际上是空的。它只包含META-INF目录


我觉得我错过了一些明显的东西,但我就是想不出来。我觉得我的pom.xml中缺少了一些东西,但在Selenium的网站上找不到任何有帮助的东西。谁能帮我一把吗

使用此POM文件运行
mvn clean install
将在本地Maven存储库中安装您的工件,而不是在依赖项中安装。这里的问题是因为Eclipse找不到您列出的Selenium依赖项而无法开发此POM所代表的项目吗?或者您正在开发另一个将这个jar用作依赖项的项目?转到
$HOME/.m2/repository/org/seleniumhq/selenium
,查看Maven是否为您指定的版本下载了selenium库。其中应该有一个jar文件,包含您需要的所有类。您安装了哪个EclipseMaven插件?您的项目中添加了Maven nature吗?@SiKing我没有使用Eclipse插件。我只是通过命令行使用Maven。这就解释了:“问题是我的Eclipse项目无法解析Selenium类。”@RyanJ我想我不理解Selenium页面上的说明。它表示,“您的pom.xml文件看起来像这样。在您为项目创建的文件夹中创建此文件。[…]现在,从命令行将CD放入项目目录,并按如下方式运行maven。[mvn clean install]这将下载Selenium及其所有依赖项,并将它们添加到项目中。”
import Selenium.*;
import Selenium.target.*;

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });

        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());

        //Close the browser
        driver.quit();
    }
}
import Selenium.By;
import Selenium.WebDriver;
import Selenium.WebElement;
import Selenium.firefox.FirefoxDriver;
import Selenium.support.ui.ExpectedCondition;
import Selenium.support.ui.WebDriverWait;