Javascript 替代 PhantomJS 进行测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14964108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 18:28:32  来源:igfitidea点击:

Alternative to PhantomJS for Testing

javascripttestingphantomjs

提问by schlingel

I'm currently trying to build a little testing suite for CI (Hudson). I've written a complex script which dynamically invokes other Scripts and populates a given DIV element.

我目前正在尝试为 CI (Hudson) 构建一个小测试套件。我编写了一个复杂的脚本,它动态调用其他脚本并填充给定的 DIV 元素。

My Selenium tests work for trivial examples (load www.google.com, search for the q-Element, etc.)

我的 Selenium 测试适用于琐碎的示例(加载 www.google.com,搜索 q-Element 等)

But when I try to run a complex test, which works with the Firefox-Driver, in my PhantomJS instance, it crashes. A segfault occurs.

但是,当我尝试在 PhantomJS 实例中运行与 Firefox 驱动程序一起使用的复杂测试时,它崩溃了。发生段错误。

My question is, how can I write tests for my frontend JS which works on a Hudson-Server which runs (headless).

我的问题是,我如何为我的前端 JS 编写测试,它在运行(无头)的 Hudson-Server 上工作。

Or is there a way of debugging what causes segfault?

或者有没有办法调试导致段错误的原因?

采纳答案by schlingel

Headless installations are possible when using Xvfb as virtual frame buffer (on Linux machines hosting the grid nodes). Ended up using this and the default Firefox.

当使用 Xvfb 作为虚拟帧缓冲区(在托管网格节点的 Linux 机器上)时,无头安装是可能的。最终使用了这个和默认的 Firefox。

回答by Corey Goldberg

Slimer.js is similar to Phantom.js, but uses Gecko rather than Webkit.

Slimer.js 类似于 Phantom.js,但使用 Gecko 而不是 Webkit。

http://slimerjs.org/

http://slimerjs.org/

回答by SDC

Phantom is an evolving product, and only relatively recently gained the ability to integrate with Selenium, so you may have hit a bug with it; have you tried reporting it to the Phantom devs?

Phantom 是一个不断发展的产品,最近才获得了与 Selenium 集成的能力,所以你可能遇到了它的错误;您是否尝试将其报告给 Phantom 开发人员?

  • Alternatives to Phantom:

    There aren't many. Zombieis one that I know of, but Phantom is head and shoulders above any other headless browser.

    You could also try using a headless virtual server to run any of the normal web browsers. (this would also have the advantage of being a more real-life test than Phantom)

  • Alternatives to Selenium:

    You could use Sahias a direct replacement to Selenium. It's capable of much the same things, but works quite differently. Your test scripts would need to be rewritten, of course.

    Phantom is designed to be scripted, so you don't actually need to use a driver tool like Selenium at all for it; you could just script it directly, or use a tool like CasperJSto write your test scripts.

  • 幻影的替代品:

    没有很多。Zombie是我所知道的,但 Phantom 比任何其他无头浏览器都高出一筹。

    您还可以尝试使用无头虚拟服务器来运行任何普通的 Web 浏览器。(这也具有比 Phantom 更真实的测试优势)

  • 硒的替代品:

    您可以使用Sahi作为 Selenium 的直接替代品。它能够做很多相同的事情,但工作方式却大不相同。当然,您的测试脚本需要重写。

    Phantom 被设计成脚本化的,所以你实际上根本不需要使用像 Selenium 这样的驱动工具;您可以直接编写脚本,或者使用CasperJS 之类的工具编写测试脚本。

回答by teknopaul

jsdomis a good alternative now, its quite mature.

jsdom现在是一个不错的选择,它相当成熟。

https://github.com/tmpvar/jsdom/

https://github.com/tmpvar/jsdom/

Its for headless testing. I don't think it will do screen shots like phantomjs did since it has no webkit or gekko renderer its pure JS.

它用于无头测试。我认为它不会像 phantomjs 那样做屏幕截图,因为它没有纯 JS 的 webkit 或 gekko 渲染器。

I found this since phantomjs segfaults and the new version will not build. slimerjs is not really headless, and its XULRunner based which FireFox just dropped, it does not work with my current FF.

我发现这是因为 phantomjs segfaults 并且新版本不会构建。slimerjs 并不是真的无头,它的 XULRunner 基于 FireFox 刚刚放弃,它不适用于我当前的 FF。

jsdom is pretty cool, it started life as an XML parser and now has a full network backend and jQuery support.

jsdom 非常酷,它最初是一个 XML 解析器,现在拥有完整的网络后端和 jQuery 支持。

API is not the same as phantomjs.

API 与 phantomjs 不同。