HtmlUnitDriver(HtmlUnit)和GhostDriver(PhantomJS)? [英] HtmlUnitDriver (HtmlUnit) vs GhostDriver (PhantomJS)?

查看:458
本文介绍了HtmlUnitDriver(HtmlUnit)和GhostDriver(PhantomJS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在选择 headless浏览器驱动程序解决方案,该解决方案将是Selenium WebDriver的某些实现. 有 GhostDriver ,它利用了 PhantomJS 在一侧的后端和 HtmlUnitDriver (基于

我们认为,PhantomJS是更强大的候选人.但是,我们并不是一无所知:)在做出决定时,我们还需要考虑其他因素和折衷吗? HtmlUnitDriver可以成为更好解决方案的其他方案?

根据我在许多无头浏览器中的经验,我会说:

HtmlUnitDriver :我遇到的所有实现中最快的,非常适合简单的静态页面,尤其是那些没有JavaScript的页面.任何遥远复杂的页面似乎都会产生问题-即使我无法详细说明理由,这也是我的实践经验.非常适合在演示页,抓取状态页等上测试Selenium功能.

PhantomJSDriver (PhantomJS + GhostDriver):与台式机浏览器相比,速度没有您希望的要快,但是比Firefox + xvfb设置起来容易得多.默认情况下,屏幕截图看起来有些奇怪,但这通常是因为PhantomJS除非明确设置,否则默认情况下是狭窄的窗口(有关原因,请阅读下文).


更新:有关PhantomJS版本的更多详细信息,来自我的其他答案. /p>

与Safari一样,PhantomJS使用 WebKit 进行渲染(例如Firefox使用Gecko)

针对不同的WebKit版本构建了不同的PhantomJS版本. PhantomJS 2.x 使用 WebKit 538.x,使其成为使用 WebKit 534.34 ,相当于Safari 5.

这可能对您来说是个问题,因为Google确定Safari 5为旧"浏览器,因此可能 SlimerJS .但是,我还没有使其足够可靠地工作.

我从来没有遇到过HtmlUnitDriver或PhantomJSDriver的可靠性问题(唯一的烦恼是 HttpClient 4.5/HtmlUnit 2.17不兼容问题).

(回答有关修改HTTP请求的评论,我个人建议坚持使用WebDriver API,并使用 proxy ,例如 http://www.guru99. com/selenium-with-htmlunit-driver-phantomjs.html https://www.quora.com/Software-Testing/How-does-PhantomJS-compare-to-Selenium

We are in the middle of choosing our headless browser driver solution that will be some implementation of Selenium WebDriver. There is the GhostDriver, which leverages the PhantomJS in the backend on the one side and HtmlUnitDriver which based on HtmlUnit on the other.

PhantomJS uses WebKit, the rendering engine of Safari, to render the pages while HtmlUnitDriver uses the Rhino engine which no other browsers use (it's just "simulating" browser behaviour. The last fact considered as a con, because the rendering behavior can differ significantly from the popular browsers.

In our opinion, PhantomJS is a much stronger candidate. But, we don't know everything :) Is there other considerations and trade-offs we should take into account with our decision? other scenarios where HtmlUnitDriver can be a better solution?

解决方案

From my experience with a number of headless browsers, I'd say:

HtmlUnitDriver: the fastest of all implementations I've come across, and perfect for simple, static pages, especially those without JavaScript. Any remotely complex page seems to produce problems - that's my practical experience even if I can't justify in detail. Perfect for testing Selenium features on demo pages, scraping status pages etc.

PhantomJSDriver (PhantomJS + GhostDriver): not as much faster as you might hope vs the desktop browsers, however, much easier to set up than Firefox + xvfb. By default screenshots can look a bit odd, but that usually turns out to be because PhantomJS defaults to a narrow window unless explicitly set (read below for why).


Update: a bit more detail on PhantomJS versions, from my other answer.

Like Safari, PhantomJS uses WebKit for rendering (e.g. Firefox uses Gecko)

Different PhantomJS versions are built against different WebKit versions. PhantomJS 2.x uses WebKit 538.x, which makes it equivalent to Safari 7 or 8. whereas PhantomJS 1.9.8 uses WebKit 534.34, which is equivalent to Safari 5.

This may be an issue for you, since Google determines Safari 5 to be an "old" browser and will therefore potentially render its search pages differently.

So ensuring you use PhantomJS 2.x can reduce the rendering differences that a lot of people report vs. desktop browsers.


Another interesting possibility is SlimerJS. However, I've not got it to work reliably enough yet.

I've never had reliability issues with either HtmlUnitDriver or PhantomJSDriver (the only annoyance one was a HttpClient 4.5 / HtmlUnit 2.17 incompatibility issue).

(In answer to the comment about modifying HTTP requests, I'd personally recommend sticking to the WebDriver API and use a proxy like BrowserMob to mutate requests and responses rather than taking advantage of browser-specific features.)

All in all, I'd advise against creating a tool or process that forces users to choose one browser over another. If possible, allow them to configure or override. For the majority of cases I'd plump for PhantomJS, as it won't let you down. However, the performance of HtmlUnit should be considered for the simplest pages.

See also (perhaps): http://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html and https://www.quora.com/Software-Testing/How-does-PhantomJS-compare-to-Selenium

这篇关于HtmlUnitDriver(HtmlUnit)和GhostDriver(PhantomJS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆