5

I'm using grunt-mocha to run unit tests via phantomJS.

I know that phantomJS has a lot of useful functionality. Can I access that from within a mocha test?

I've looked in the obvious places such as the window object to see if I can somehow access the page object, but nothing seems obvious.

Specifically, I'd like to render a screenshot of the page under test.

4

2 に答える 2

1

これは、ドキュメントでは「スクリーン キャプチャ」と呼ばれています。

WebPage重要な部分は、ブラウザ オブジェクトではなく、への参照が必要だということですwindow(これは、JavaScript がブラウザ内から通常見ることができるものをエミュレートするだけです)。

var page = require('webpage').create();
page.open('http://github.com/', function () {
    page.render('github.png');
    phantom.exit();
});
于 2013-03-28T11:51:38.750 に答える