WAIN 中是否有在每次页面加载时执行的页面检查器?
我正在使用 WATIR 和 WATIN 编写自动化脚本。 Watir 有一种称为页面检查器的东西,它是在每次页面加载时运行的代码片段。 WAIN 有类似的东西吗?我希望在每次页面加载时运行一段代码。通常,这用于检查页面错误或页面加载图像。
I am writing automation scripts using WATIR and WATIN. Watir has something called page checkers, which are code snippets that run on each page load. Is there something similar in WATIN ? I want a piece of code to run on each page load. Generally this is used to check for page errors or page loading images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
判断页面何时加载并不是那么容易。我很快用谷歌搜索了您提到的 Watir 中的页面检查器,并找到了 一篇关于 Watir 中页面检查器的文章。请参阅文章下面的第一条评论。 AFAIK 在 WatiN 中确实很相似。
不幸的是,我在 WatiN 中没有看到任何类似的功能(在内部调用
WaitForComplete
后不会触发任何事件。您可以做的最简单的事情就是子类化,例如IE
类:但是,情况与所提到的评论中描述的类似(运行比仅页面加载更频繁),
我认为更好的方法是使用
Page
类 。 WatiN 库。 watin.org 网页示例:要运行该代码,您需要以下类:
基本上,您需要实现
VerifyDocumentProperties
上面的代码将检查是否HomeLink
。 > 存在,但也许您想检查DocumentationLink
是否存在等。第二件事是修改对VerifyDocumentProperties
的调用。现在,如果验证失败,Exception<。 /code> 将在调用
ie.Page()
(其中 T 是 WatinBaseClass 的子类)后抛出,即使您不需要使用“页面检查器” 。 ,使用
Page
类仍然非常有用并且可以澄清代码,所以我真的推荐使用它。我很遗憾在开始与 WatiN 合作时没有发现它。It is not really that easy to tell when page loads. I quickly googled about that page checkers in Watir, that you mentioned and found an article about page checkers in Watir. See first comment bellow the article. AFAIK it's really similar in WatiN.
Unfortunately, I don't see any similar functionality in WatiN (no event is fired after internal call to
WaitForComplete
. The easiest thing you could do is to subclass eg.IE
class:However, the situation will be similar to described in mentioned comment (runs a lot more regularly than just page load).
I think that better approach would be using
Page
class from WatiN library. It is well documented. Example for watin.org webpage:To run that code you need following classes:
Basically you need to implement
VerifyDocumentProperties
. Above code will check ifHomeLink
exists, but maybe you would like to check ifDocumentationLink
exists etc. The second thing is to modify call toVerifyDocumentProperties
. Now, if verification fails,Exception
will be thrown after callingie.Page<T>()
(where T is a subclass of WatinBaseClass).In my opinion, even if you don't need to use "page checkers", using
Page
class is still really useful and clarifies the code, so I really recommend using it. I regret that I haven't discovered it when I was starting work with WatiN.