javascript - 我可以从 mocha/phantomjs 单元测试中获取页面截图吗?

标签 javascript unit-testing phantomjs mocha.js

我正在使用 grunt-mocha 通过 phantomJS 运行单元测试。

我知道 phantomJS 有很多有用的功能。我可以从 mocha 测试中访问它吗?

我查看了明显的地方,例如 window 对象,看看我是否可以以某种方式访问​​页面对象,但似乎没有什么明显的地方。

具体来说,我想呈现被测页面的屏幕截图。

最佳答案

这叫做 "Screen Capture" in the documentation .

重要的部分是您需要对 WebPage 的引用,而不是浏览器 window 对象(这只是模拟 JavaScript 通常可以从浏览器内部看到的内容)。

var page = require('webpage').create();
page.open('http://github.com/', function () {
    page.render('github.png');
    phantom.exit();
});

关于javascript - 我可以从 mocha/phantomjs 单元测试中获取页面截图吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15680725/

相关文章:

javascript - 听说过一个框架/应用程序只从数据库返回您需要的内容吗?

c# - 如何在没有 ControllerContext 的情况下从 IIdentity 模拟 GetUserId 和 IsAuthenticated

javascript - 如何覆盖 window.screen?

php - Zend Framework 2 数据库测试 - 非对象上的 canCallMagicCall()

php - 在 WIndows Apache 2.4 中安装 casperJS 和 phantomJS 向 PHP 传递数据

javascript - 使用 clipRect() 后设置 PhantomJS 捕获整个屏幕

javascript - 处理动态表格

javascript - 选择输入元素的子元素

javascript - 将附加 SDK 面板链接到工具栏按钮

c# - 那些单元测试没问题吗?