Groovy 如何在不使用Grape依赖关系管理的情况下使用Geb

Groovy 如何在不使用Grape依赖关系管理的情况下使用Geb,groovy,selenium-webdriver,geb,Groovy,Selenium Webdriver,Geb,我是Geb的新手,尝试在进一步使用之前做一个快速测试来评估它。由于代理权限等原因,我不想使用Grape。因此,我尝试手动下载所需的JAR,并尝试在命令行上指定它们 但是,在执行此操作时,我收到以下未找到WebDriverException的类: C:\geb-test>groovy -cp geb-core-0.9.2.jar;selenium-htmlunit-driver-2.35.0.jar;selenium-support-2.35.0.jar GoogleTest Caught:

我是Geb的新手,尝试在进一步使用之前做一个快速测试来评估它。由于代理权限等原因,我不想使用Grape。因此,我尝试手动下载所需的JAR,并尝试在命令行上指定它们

但是,在执行此操作时,我收到以下未找到WebDriverException的类:

C:\geb-test>groovy -cp geb-core-0.9.2.jar;selenium-htmlunit-driver-2.35.0.jar;selenium-support-2.35.0.jar GoogleTest
Caught: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriverException
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriverException
        at GoogleTest.run(GoogleTest.groovy:3)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriverException
        ... 1 more

C:\geb-test>
我需要额外的罐子吗?如果是的话,是哪一个?我尝试了其他一些方法,但没有任何乐趣——正如我所指出的,WebDriverException在selenium-api-2.35.0.jar中,但没有任何区别

以下是从一些版本信息开始的详细信息:

  • Groovy版本:2.1.7 JVM:1.7.0\u 40供应商:Oracle公司操作系统:Windows 7
首先,我使用的是我放在一个名为GoogleTest.groovy的文件中的:

import geb.Browser

Browser.drive {
    go "http://google.com/ncr"

    // make sure we actually got to the page
    assert title == "Google"

    // enter wikipedia into the search field
    $("input", name: "q").value("wikipedia")

    // wait for the change to results page to happen
    // (google updates the page dynamically without a new request)
    waitFor { title.endsWith("Google Search") }

    // is the first link to wikipedia?
    def firstLink = $("li.g", 0).find("a.l")
    assert firstLink.text() == "Wikipedia"

    // click the link 
    firstLink.click()

    // wait for Google's javascript to redirect to Wikipedia
    waitFor { title == "Wikipedia" }
}
然后,基于这些注释,我确保@Grab注释中提到了jar。这导致我的测试目录包含以下文件:

07/11/2013  10:46    <DIR>          .
07/11/2013  10:46    <DIR>          ..
06/11/2013  14:51           460,165 geb-core-0.9.2.jar
06/11/2013  15:13               711 GoogleTest.groovy
06/11/2013  14:55            56,189 selenium-htmlunit-driver-2.35.0.jar
06/11/2013  14:54           130,535 selenium-support-2.35.0.jar
               4 File(s)        647,600 bytes

我开始怀疑问题是否是Groovy'-cp'命令行中的多个JAR。我现在正试图将JAR放在${user.home}.groovy\lib目录中。但最后我得到了一个未定义的GebException类。也许你必须使用葡萄才能有机会让它发挥作用。:/让我知道。

好吧,我让步了,决定尝试强制代理身份验证工作

我决定试用Chrome驱动程序,因此我的注释如下所示:

@Grapes([
    @Grab("org.gebish:geb-core:0.9.2"),
    @Grab("org.seleniumhq.selenium:selenium-chrome-driver:2.26.0"),
    @Grab("org.seleniumhq.selenium:selenium-support:2.26.0")
])
最终的结果是,存在一个重要的依赖链,所以手动尝试可能是不可取的。如果您确实希望这样做,那么用下面的代码准备您的类路径

从一个空的葡萄存储库出发,我得到了这个(以“葡萄列表”显示):

  • cglib cglib nodep[2.1_3]
  • com.google.guavaguava[13.0.1]
  • com.google.guava-guava-parent[13.0.1]
  • commons编解码器commons编解码器[1.6]
  • 公共记录公共记录[1.1.1]
  • net.java.dev.jna jna[3.4.0]
  • net.java.dev.jna平台[3.4.0]
  • org.apacheapache[4,7,9]
  • org.apache.commons-commons-exec[1.1]
  • org.apache.commons-commons-parent[17,22,5]
  • org.apache.httpcomponents-httpclient[4.2.1]
  • org.apache.httpcomponents httpcomponents客户端[4.2.1]
  • org.apache.httpcomponents httpcomponents核心[4.2.1]
  • org.apache.httpcomponents-httpcore[4.2.1]
  • org.apache.httpcomponents项目[6]
  • org.gebish geb ast[0.9.2]
  • org.gebish geb核心[0.9.2]
  • org.gebish geb隐式断言[0.9.2]
  • org.gebish geb waiting[0.9.2]
  • org.json json[20080701]
  • org.seleniumhq.selenium-selenium-api[2.26.0]
  • org.seleniumhq.selenium铬驱动程序[2.26.0]
  • org.seleniumhq.selenium父代[2.26.0]
  • org.seleniumhq.selenium远程驱动程序[2.26.0]
  • org.seleniumhq.selenium硒支持[2.26.0]
  • org.sonatype.oss oss父项[7]
@Grapes([
    @Grab("org.gebish:geb-core:0.9.2"),
    @Grab("org.seleniumhq.selenium:selenium-chrome-driver:2.26.0"),
    @Grab("org.seleniumhq.selenium:selenium-support:2.26.0")
])