HtmlUnit +生产中的硒

发布于 2024-12-29 20:35:23 字数 249 浏览 1 评论 0原文

我目前正在使用 HtmlUnit 和 Selenium 在我的生产代码中驱动它 (WebDriver)。

我正在使用这些库以编程方式与各种网站进行扫描和交互,并且取得了一些成功并且没有遇到内存问题(确保会话始终被清理)。

我想知道这些库是否适合生产环境或不建议使用。由于有关自动化测试的大量信息而不是我如何使用它们,因此很难通过 Google 找到它。

我意识到这是一个相当普遍的问题,但我正在寻求有关这些库和可能更好的替代方案的建议。

I am currently using HtmlUnit and Selenium to drive it (WebDriver) within my production code.

I am scaping and interacting with various websites programmatically with these libraries and am having some success and not experiencing memory issues (ensuring sessions are always cleaned up).

I am wondering if these libraries are okay for a production environment or recommended against. This is difficult to find via Google due to the enormous amount of information about automated testing rather than how I am using them.

I realise this is a fairly generic question, but I am seeking advice on these libraries and potentially better alternatives.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半世蒼涼 2025-01-05 20:35:23

WebDriver 和 Selenium 非常适合生产环境。我在多机器/多数据中心分布式网格上广泛使用它们已有两年了,并且绝对没有我们无法应对的性能或稳定性问题。

我们首选的驱动程序是 Firefox 驱动程序(比 HTMLUnit 重,并且更难配置),并且我们必须调整网格以了解可以运行多少个实例。我们的最大稳定性是每个核心 1

我们的 selenium/webdriver 实例现在已经 24/7 运行了 2 年(使用 selenium 1 一年,其他增量迁移 selenium 2/ WebDriver)并进行了适当的监控(您应该监控内存使用情况) /CPU 使用率)和一堆负载测试,我们已经达到了良好的水平,我们已经经历了几个月而不重新启动进程

我们也广泛使用了 HTMLUnit,并且对这个库同样满意

。我的帖子是:是的,这些库已经可以投入生产了。但是,与所有生产软件一样,您必须对它们的使用进行基准测试,以找到实现最佳稳定性的适当配置。我建议您在生产中使用 Selenium Grid,这是并行化流程的好方法

WebDriver and Selenium are perfectly suited for production environnement. I use them quite extensively for 2 years now on a multi-machines/multi-datacenters distributed grid and had absolutely no performance nor stability problems we couldn't have coped with.

Our preferred driver is the Firefox one (heavier than HTMLUnit, and harder to configure), and we had to tweak the grid to understand how many instances we can run. Our maximum for stability was 1 per core

Our selenium/webdriver instances have run 24/7 for 2 years now (1 year with selenium 1, and the other migrating selenium 2/ WebDriver incrementally) and with an appropriate monitoring (you should monitor Memory Usage/CPU Usage) and a bunch of load testing, we had reached the good level where we have experienced several monthes without restarting a process

We've used HTMLUnit extensively too, and are equally satisfied with this library

The essential point of my post is : YES, these library are production-ready. But, as all production software, you'll have to benchmark their use to find the appropriate configuration for the optimal stability. I recommend you to use the Selenium Grid in production, which is a great way to parallelize process

凉城已无爱 2025-01-05 20:35:23

我在生产中使用 HtmlUnit 进行类似的操作,并且遇到了很多问题 - 主要是与性能相关。目前,我切换到 HtmlUnit 2.10 的快照版本,其中实现了一些对我来说重要的性能改进(例如,在 上将 ArrayList.contains() 替换为 HashSet.contains() DomNode.addDomChangeListener())。

尽管如此,JavaScript 密集的页面上的 CPU 负载仍然相当高。通常,我无法在双核 Linux 机器上同时运行 10 个以上的程序。我相信 HtmlUnit 仅在解释器模式下使用 Rhino(JavaScript 引擎),这非常慢。另外,您需要小心释放 HtmlUnit 使用的所有资源以避免内存泄漏。

总而言之,值得注意的是,HtmlUnit 设计用于运行相对较短的测试用例,而不是长期运行的服务器应用程序。可以对其进行足够的调整,使其易于管理,但肯定可以做得更好。

我发现有希望的另一种方法是 phantom-js,它是 WebKit 浏览器的无头版本,原生应用程序速度更快关于运行 JavaScript。

I'm using HtmlUnit for something similar in production and have had quite a bit of issues - mostly performance related. Currently I switched to snapshot version of HtmlUnit 2.10 where some important for me performance improvements were implemented (e.g. replacing ArrayList.contains() with HashSet.contains() on DomNode.addDomChangeListener()).

Still, the CPU load is quite high on JavaScript-heavy pages. Typically, I can't run more than 10 of them simultaneously on dual core Linux box. I believe HtmlUnit using Rhino (JavaScript engine) in interpreter mode only, which is pretty slow. Also, you need to be careful with releasing all resources used by HtmlUnit to avoid memory leaks.

All in all, it certainly noticeable that HtmlUnit was designed to run relatively short lived test cases and not long running server applications. It's possible to tweak it enough so it's manageable but certainly it could have been better.

Another approach I found promising is phantom-js, which is headless version of WebKit browser, native app which is much faster on running JavaScript.

人事已非 2025-01-05 20:35:23

一般来说,使用你的测试“直觉”。 WebDriver 和 HTMLUnit 的作用是模拟真实用户在网页中执行某些操作。

我个人的直觉告诉我,我应该尽可能少地进行生产测试。因此,如果我的网络应用程序仍然存在,我个人只会使用这些工具进行验证。

是的,这是对通用问题的通用答案,但试试这个:

聚集负责网络应用程序的人员并询问他们:

  • 应该在生产中进行测试吗? (所以总有一些客户会看到这些测试数据的可能性很小)

  • 如果是,应该在生产中测试什么?

  • 如果是,是否应该自动化?

然后你就有了答案;)

Generally, use your testing "gut feeling" about that. What WebDriver and HTMLUnit does is, that it simulates real user performing some actions in the webpage.

My personal gut feeling says, that I should do as less production testing, as possible. So I personally would use these tools only for verification, if my webapp is still alive.

Yes, its generic answer for generic question, but try this:

Gather around people responsible for the webapp and ask them:

  • Should be it tested on production? (so there is always slight chance, that some customers will see those test data)

  • If yes, what should be tested on production?

  • If yes, should it be automated?

And then you have answer ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文