有没有办法直观地查看 htmlunit 是否执行正确的命令?
有没有办法直观地查看 htmlunit 是否执行正确的命令?我对使用 htmlunit 有一个硬性要求。我只是不知道它是否正确填写了所有表格。
Is there a way to visually see if htmlunit is performing the correct commands? I have a hard requirement to use htmlunit. I just don't know if it's filling out all the form correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非您自己编写日志记录和某种显示代码,否则无法查看 HtmlUnit 正在做什么。我过去曾这样做过,这在一定程度上很有帮助,但实际上不可能通过视觉反馈来了解 HtmlUnit 正在做什么。即使使用日志记录,也不可能知道 HtmlUnit 正在做什么或哪里出了问题的每一个细节,因此这是一项极其耗时的任务。我什至诉诸于输出当前查看的页面,但这非常有限,因为 html 页面无法告诉 HtmlUnit 在该页面上执行的实际“命令”。
另一种方法是使用 Selenium,它以可视化方式执行您的“命令”,您可以通过观察立即看到哪里出了问题。
It's not possible to view what HtmlUnit is doing unless you code logging and some sort of display yourself. I have done this in the past, and it's helpful to a certain degree but it's not really possible to have a visual feedback to see what HtmlUnit is doing. Even with logging, it's not possible to know every single detail what HtmlUnit is doing or where it goes wrong, so it's an extremely time consuming task. I even resorted to outputting the current page viewed but this is pretty limited as an html page cannot tell the actual "commands" HtmlUnit is executing on that page.
Another approach would be to use Selenium, which executes your "commands" in a visual manner you can see where things go wrong instantly by watching it.
HTMLunit 被设计为无 GUI 浏览器,根据您的要求,您可以考虑使用 Webdriver 或 Watir 或 Selenium 等此类工具。如果您使用 Ruby,请看一下 Celerity,它将 HtmlUnit 包装在 Watir-ish API 中;事实上,Celerity 本身是由 Culerity 包装的,它集成了 Celerity 和 Cucumber,您可能对此更感兴趣。
HTMLunit is designed to be GUI less browser and for your requirements you can consider using Webdriver or Watir or Selenium etc such tools. In case you are in to Ruby, take a look at Celerity which wrapped HtmlUnit in a Watir-ish API; In fact Celerity is itself being wrapped by Culerity, which integrates Celerity and Cucumber and that could be of more interest to you.
是的。您可以使用 webscarab、fiddler 等代理查看 HTTP 流量。
确保以下
通过构造函数将代理详细信息设置为 Htmlunit。我认为是 webclient
确保您信任所有证书或将代理证书添加到信任库
Yes. you can see the HTTP traffic by using proxy like webscarab, fiddler..etc.
Make sure the following
Set the proxy details to Htmlunit via contsructor. I think it is webclient
Make sure you either trust all the certs or add proxy certificate to truststore
“正确的命令”是什么意思? HtmlUnit 本身不会为您提供其正在执行的操作的运行描述(如果这就是您的意思)。正如 suthasankar 所说,HtmlUnit 是一个无头浏览器(故意如此),永远不会为您提供观看页面飞驰而过的酷炫 Watir 体验。
每当我想知道测试执行期间发生了什么时,我都会在测试代码的各个点添加日志记录语句,然后在控制台中观察它们。您可以将消息发送到任何其他监控系统。
然后围绕您感兴趣的“命令”编写包装器并不需要太多时间,例如“getPage”和按钮单击以及表单条目等。
What do you mean by "correct commands"? HtmlUnit itself won't give you a running description of what it's doing, if that's what you mean. As suthasankar says, HtmlUnit is a headless browser (intentionally so) and will never give you the cool Watir experience of watching pages fly by.
Any time I've wanted to know what's happening during a test's execution, I have added logging statements at various points in the test code and then watched them in the console. You could send messages to any other monitoring system you instead.
It wouldn't take much to then write wrappers around the "commands" you're interested in, like "getPage" and button clicks and form entries and the like.