Can I get a screenshot of the page from mocha / phantomjs unit test?

I use grunt-mocha to run unit tests through phantomJS.

I know that phantomJS has many useful features. Can I access this from a mocha test?

I looked at obvious places, such as an object window, to see if I could access the page object in any way, but nothing seemed obvious.

In particular, I would like to take a screenshot for the tested page.

+5
source share
2 answers

This is called "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();
});
+1

forked ​​ grunt-mocha. . "" https://github.com/bjfletcher/grunt-mocha.

, , Kelly grunt-mocha npmjs.org: https://github.com/kmiyashiro/grunt-mocha/pull/109

+1

All Articles