我正在使用 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/