Groovy Geb手册上第一个未执行的示例
我有以下设置:Groovy Geb手册上第一个未执行的示例,groovy,selenium,webdriver,geb,Groovy,Selenium,Webdriver,Geb,我有以下设置: 已安装JDK和JRE 6u29 已安装selenium standalone 2.8 Groovy 1.8.3 Geb 0.6.1 仅使用GroovyConsole,我尝试执行Geb手册中给出的第一个示例: import geb.Browser Browser.drive { go "http://google.com/ncr" // make sure we actually got to the page assert title == "Google" /
- 已安装JDK和JRE 6u29
- 已安装selenium standalone 2.8
- Groovy 1.8.3
- Geb 0.6.1
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.waiting.WaitTimeoutException:条件未在5.0中传递
秒
这个例子有什么不对劲吗?我做错什么了吗?这是非常令人沮丧的,因为第一个示例甚至无法运行 脚本正在搜索框中输入
wikipedia
,但没有点击googlesearch
按钮启动搜索
如果您添加:
// hit the "Google Search" button
$("input", name: "btnG").click()
紧接着
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
你会走得更远一点 该示例使用了Google中的自动加载功能,即在键入搜索时显示搜索结果,因此您无需单击搜索按钮。当您运行测试时,您应该看到搜索结果被显示,并且Wikipedia链接是第一个 您得到的WaitTimeoutException很可能是因为浏览器在到达Wikipedia页面后关闭过快。要解决这个问题,只需更新waitFor调用,使其在关闭浏览器之前等待更长时间,即
waitFor(10) (at WikipediaPage)
或者,如果您在调试模式下运行gradle,则该过程会慢得多,因此允许测试在浏览器终止之前检查标题
gradlew firefoxTest --debug --stacktrace
我遇到了与你同样的问题 待发行的第一批: 第一次等待可以通过J.Levine的回答来解决。添加: $(“输入”,名称:“btnG”)。单击() 之后: $(“输入”,名称:“q”).value(“维基百科”) 第二个等待发布: Wikipedia从google打开的页面标题与Wikipedia主页不同。在主页上,它是主页上的
Wikipedia
(谷歌打开的是免费百科全书Wikipedia.
因此,改变:
waitFor{title==“Wikipedia”}致:
waitFor{title==“维基百科,免费百科全书”}
}
这应该可以解决第二个等待问题。上面的任何一个都不适合我。经过一些调试后,我得到了如下代码:
Browser.drive {
go "http://google.com"
// 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")
assert firstLink.text() == "Wikipedia, the free encyclopedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
waitFor { title == "Wikipedia, the free encyclopedia" }
}