Geb 手册上的第一个示例未执行
我有以下设置:
- 安装了 JDK & JRE 6u29
- 安装了 selenium 独立版 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"
// 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 中条件未通过 秒
这个例子有问题吗?我做错了什么吗?这非常令人沮丧,因为第一个示例甚至无法运行!
I have the following setup:
- installed JDK & JRE 6u29
- installed selenium standalone 2.8
- Groovy 1.8.3
- Geb 0.6.1
Using just the GroovyConsole i tried to execute the very first example given in the Geb manual :
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" }
}
but am getting the following error:
WARNING: Sanitizing stacktrace:
geb.waiting.WaitTimeoutException: condition did not pass in 5.0
seconds
Is there something wrong w/ the example? Am I doing something incorrect? this is very frustrating seeing as how the VERY first example won't even run!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该脚本将
wikipedia
输入到搜索框中,但并未点击Google 搜索
按钮来启动搜索。如果你加上:
就在
你会走得更远一点之后。
The script is entering
wikipedia
into the Search box, but it's not hitting theGoogle Search
button to kick off the search.If you add:
right after
you'll get a little farther.
该示例利用了 Google 中的自动加载功能,在您输入搜索内容时就会显示搜索结果,因此您无需单击搜索按钮。运行测试时,您应该看到显示搜索结果,并且维基百科链接位于第一个。
您收到的 WaitTimeoutException 很可能是因为浏览器在到达维基百科页面后关闭得太快。要解决这个问题,只需更新 waitFor 调用以使其在关闭浏览器之前等待更长时间,即,或者
,如果您在调试模式下运行 gradle,该过程会慢得多,因此允许测试在浏览器终止之前检查标题
The example makes use of the auto load feature in Google whereby search results are displayed as you type in the search, hence you don't need to click on the search button. When you run the test, you should see that the search results are displayed and the Wikipedia link is the first.
The WaitTimeoutException you are getting is most probably because the browser closes too quickly after arriving at the Wikipedia page. To fix that, just update the waitFor call to make it wait longer before closing the browser i.e.
Alternatively, if you run gradle in debug mode, the process is much slower and hence allows the test to check for the title before the browser is terminated
我遇到了与您遇到的同样的问题。
第一个 WaitFor 问题:
第一个等待可以通过 J. Levine 的回答来解决。添加:
之后:
第二个WaitFor问题:
维基百科从google打开的页面标题与维基百科主页不同。在主页上,它是主页上的Wikipedia<title></code> (Google 打开的是 <code><title>Wikipedia,免费的百科全书<title>。</code>
所以改变:
这应该可以解决第二个等待
I had the same problem you are experiencing.
The first WaitFor issue:
The first wait for can be fixed by J. Levine's answer. Adding:
after:
The second WaitFor issue:
The title of the page that Wikipedia opens to from google is different from the Wikipedia Homepage. On the homepage it is
<title>Wikipedia<title>
on the main page(which google opens to is<title>Wikipedia, the free encyclopedia<title>.
So change:
And that should fix the second wait issue
以上都不适合我。经过一些调试后,我得到的代码工作如下:
None of the above worked for me. After some debugging I got the code working like this: