Selenium Maven设置 - 一个空瓶子

时间:2015-02-27 17:38:15

标签: java eclipse maven selenium

我尝试使用此处的推荐Maven说明设置Java Selenium测试:

http://docs.seleniumhq.org/docs/03_webdriver.jsp

在这里:

http://docs.seleniumhq.org/download/maven.jsp

我已经安装并使用了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>

使用

mvn clean install

运行没有任何错误。创建目标目录,其中包含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();
    }
}

课程&#34; WebDriver&#34;,&#34; WebElement&#34;,&#34; WebDriverWait&#34;,&#34; ExpectedCondition&#34;无法解决。尝试使用示例中的导入

import Selenium.By;
import Selenium.WebDriver;
import Selenium.WebElement;
import Selenium.firefox.FirefoxDriver;
import Selenium.support.ui.ExpectedCondition;
import Selenium.support.ui.WebDriverWait;
一切都失败了。

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

我觉得我错过了一些明显的东西,但我无法弄明白。我觉得我在pom.xml中遗漏了一些东西,但是我在Selenium的网站上找不到任何有用的东西。任何人都可以帮我一把吗?

0 个答案:

没有答案