什么是“官方”?如何将 Selenium 2 (Selenium WebDriver) 与 Maven 一起使用?

发布于 2024-11-08 21:38:13 字数 3794 浏览 0 评论 0原文

我只是想使用 Maven 使基本的 Selenium2Example 与 Firefox 4 一起使用来获取 Selenium jar:

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");

        // 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());

        //Close the browser
        driver.quit();
    }
}

如果我去那里: http://code.google.com/p/selenium/wiki/UsingWebDriver,它说我应该尝试这样的依赖项:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium</artifactId>
    <version>2.0b3</version>
</dependency> 

但是在任何存储库中都找不到最新的 jar,最后一个有效的版本(找到所有依赖项)是“2.0a4”(2.0a5 到 2.0a7 和 2.0b1 到 2.0b3 缺少主 jar 或缺少依赖项),并且这个“2.04”版本没有正确的类使示例发挥作用。

如果我去那里: http://seleniumhq.org/docs/03_webdriver.html#chapter03-参考,它说我应该使用此依赖项:

<dependency>
    <groupId>org.seleniumhq.webdriver</groupId>
    <artifactId>webdriver-firefox</artifactId>
    <version>0.9.7376</version>
</dependency>

它使示例可以编译,但此版本自 2009 年 10 月以来尚未更新,并且它不能在 Firefox 4 上运行(请参阅 http://repo1.maven.org/maven2/org/seleniumhq/webdriver/webdriver-firefox/< /a>)

如果我去那里 http://seleniumhq.org/download/maven.html ,它说我应该尝试类似的操作:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>...</version>
</dependency> 

但是 2.0b3 版本也不起作用(缺少依赖项)。这是错误消息:

23/05/11 22:09:07 CEST: Build errors for first-webdriver-test; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project first-webdriver-test: Unable to get dependency information for org.apache.httpcomponents:httpcore:jar:4.0.1: Failed to process POM for org.apache.httpcomponents:httpcore:jar:4.0.1: Non-resolvable parent POM org.apache.httpcomponents:httpcomponents-core:4.0.1 for org.apache.httpcomponents:httpcore:4.0.1: Failed to resolve POM for org.apache.httpcomponents:httpcomponents-core:4.0.1 due to Missing:
----------
1) org.apache.httpcomponents:httpcomponents-core:pom:4.0.1
----------
1 required artifact is missing.

for artifact: 
  org.apache.httpcomponents:httpcomponents-core:pom:4.0.1

from the specified remote repositories:
  central (http://repo1.maven.org/maven2, releases=true, snapshots=false)

我不知道这个错误的含义,因为我可以在这里找到请求的pom: http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.0.1/httpcomponents -core-4.0.1.pom

因此,我现在可以使该示例正常工作的唯一方法是手动下载 2.0b3 jar。

有人成功地让它与 Maven 一起工作吗?

I'm just trying to make the basic Selenium2Example work with Firefox 4 using Maven to get the Selenium jars :

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");

        // 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());

        //Close the browser
        driver.quit();
    }
}

If I go there : http://code.google.com/p/selenium/wiki/UsingWebDriver, it says I should try a dependency like this :

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium</artifactId>
    <version>2.0b3</version>
</dependency> 

but the latest jars can be found in no repositories, the last version which works (with all dependencies found) is "2.0a4" (2.0a5 to 2.0a7 and 2.0b1 to 2.0b3 have missing main jars or missing dependencies), and this "2.04" version doesn't have the right classes to make the example work.

If I go there : http://seleniumhq.org/docs/03_webdriver.html#chapter03-reference, it says I should use this dependency :

<dependency>
    <groupId>org.seleniumhq.webdriver</groupId>
    <artifactId>webdriver-firefox</artifactId>
    <version>0.9.7376</version>
</dependency>

It makes the example compile, but this release hasn't been updated since october 2009, and it doesn't run with Firefox 4 (see http://repo1.maven.org/maven2/org/seleniumhq/webdriver/webdriver-firefox/)

If I go there http://seleniumhq.org/download/maven.html, it says I should try something like :

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>...</version>
</dependency> 

But the 2.0b3 version doesn't work either (missing dependencies). Here is the error message :

23/05/11 22:09:07 CEST: Build errors for first-webdriver-test; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project first-webdriver-test: Unable to get dependency information for org.apache.httpcomponents:httpcore:jar:4.0.1: Failed to process POM for org.apache.httpcomponents:httpcore:jar:4.0.1: Non-resolvable parent POM org.apache.httpcomponents:httpcomponents-core:4.0.1 for org.apache.httpcomponents:httpcore:4.0.1: Failed to resolve POM for org.apache.httpcomponents:httpcomponents-core:4.0.1 due to Missing:
----------
1) org.apache.httpcomponents:httpcomponents-core:pom:4.0.1
----------
1 required artifact is missing.

for artifact: 
  org.apache.httpcomponents:httpcomponents-core:pom:4.0.1

from the specified remote repositories:
  central (http://repo1.maven.org/maven2, releases=true, snapshots=false)

I don't know the meaning of this error, since I can find the requested pom here : http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.0.1/httpcomponents-core-4.0.1.pom

So the only way I can make the example work for now, is manually downloading the 2.0b3 jars.

Does anybody succeed in making it work with Maven ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫性小仙女 2024-11-15 21:38:13

从 RC2 开始,您只需要:

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium</artifactId>
            <version>2.0rc2</version>
            <type>pom</type>
        </dependency>

Since RC2, you just need:

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium</artifactId>
            <version>2.0rc2</version>
            <type>pom</type>
        </dependency>
如此安好 2024-11-15 21:38:13

对我来说,这是有效的(使用 Maven 2.2.1):

  <dependency>
     <groupId>org.seleniumhq.selenium</groupId>
     <artifactId>selenium</artifactId>
     <version>2.0b3</version>
     <type>pom</type>
  </dependency>

注意这一行: pom

另外,我必须添加对 junit 库的依赖才能让它通过一些肯定的例外,但你可能不需要这个。

For me this is working (with Maven 2.2.1):

  <dependency>
     <groupId>org.seleniumhq.selenium</groupId>
     <artifactId>selenium</artifactId>
     <version>2.0b3</version>
     <type>pom</type>
  </dependency>

Notice this line: <type>pom</type>

Also, I had to add the dependency on the junit library to get it to pass some surefire exceptions, but you might not need this.

怎樣才叫好 2024-11-15 21:38:13

使用 RC3,您需要:

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.0rc3</version>
</dependency>

包含所有 jar

With RC3 you need:

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.0rc3</version>
</dependency>

to include all the jar

千里故人稀 2024-11-15 21:38:13

对我来说,这有效:

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.8.2</version>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.29.1</version>
</dependency> 

  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.29.1</version>
</dependency>

<dependency> 
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>               
</dependency>

For me, this works:

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.8.2</version>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.29.1</version>
</dependency> 

  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.29.1</version>
</dependency>

<dependency> 
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>               
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文