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

时间:2013-11-07 00:25:45

标签: 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: 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_40供应商:Oracle Corporation操作系统:Windows 7

首先,我使用的是simple geb inline scripting example,我将其放入名为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" }
}

然后基于geb install instructions我确定我有@Grab注释中提到的罐子。这导致我的测试目录包含以下文件:

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

然后为了完整性,我尝试上面提到的命令行执行:

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>

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

1 个答案:

答案 0 :(得分:1)

好吧,我放弃了,并决定尝试强制代理身份验证工作。

我决定尝试使用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.guava guava [13.0.1]
  • com.google.guava guava-parent [13.0.1]
  • commons-codec commons-codec [1.6]
  • commons-logging commons-logging [1.1.1]
  • net.java.dev.jna jna [3.4.0]
  • net.java.dev.jna platform [3.4.0]
  • org.apache apache [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-client [4.2.1]
  • org.apache.httpcomponents httpcomponents-core [4.2.1]
  • org.apache.httpcomponents httpcore [4.2.1]
  • org.apache.httpcomponents project [6]
  • org.gebish geb-ast [0.9.2]
  • org.gebish geb-core [0.9.2]
  • org.gebish geb-implicit-assertions [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 selenium-chrome-driver [2.26.0]
  • org.seleniumhq.selenium selenium-parent [2.26.0]
  • org.seleniumhq.selenium selenium-remote-driver [2.26.0]
  • org.seleniumhq.selenium selenium-support [2.26.0]
  • org.sonatype.oss oss-parent [7]