0
@Grapes([
    @Grab("org.codehaus.geb:geb-core:0.7.2"),
    @Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.15.0"),
    @Grab("org.seleniumhq.selenium:selenium-support:2.15.0")
])
import geb.Browser

Browser.drive {
  // Load the page
  go "http://www.whu.edu.cn"

  // $("a") returns all hyperlinks on the page, similar to jQuery
  $("a").each { a ->
     // Display the required link properties and attributes
     println """
        The link to '${a.@href}' with text '${a.text()}' is at location (${a.x}, ${a.y}),
        with a height of ${a.height}px and a width of ${a.width}px.
     """
  }
}

我刚刚在 Eclipse 中创建了我的第一个 Groovy 项目,并在项目中创建了我的第一个 Groovy 类。为课程编写的所有内容都如上。当我运行脚本时,它没有抛出任何错误,也不会及时终止。

它是否试图下载所有带注释的依赖项?如果是这样,是否每次运行时都需要下载依赖项?还是一劳永逸?

4

1 回答 1

2

当你运行它时,它会检查每个带有@Grab 注释的库的正确版本是否已下载,如果没有,将尝试下载它。不仅是命名库,还有那些库的依赖项。

所以,是的,第一次运行它可能需要一些时间。随后的运行应该花费更少的时间。

请注意,这只是为了方便。您还可以下载所需的库,并在“groovy”命令的 -classpath 参数中指定它们(并删除 Grapes/Grab 结构)。

有关详细信息,请参阅http://groovy.codehaus.org/Grape

于 2012-12-14T04:24:46.387 回答