How to capture screenshot of entire page using NightwatchJS

959 Views Asked by At

I would like to capture screenshot of entire page. The dimension that I would like to capture is width - 1200px, height - 5000px. When I set resizeWindow(1200, 5000) it doesn't expand the window beyond my desktop screen height which is 1080px.

2

There are 2 best solutions below

1
On

In your nightwatch.json please add "resolution": "1200x5000":

"yourPlatformName": {
    "selenium_port": ...,
    "selenium_host": ...,
    "desiredCapabilities": {
        "os": "...",
        "os_version": "...",
        "browserName": "...",
        "resolution": "1200x5000"
        //...
    }
}

Does it works?

0
On

Doesn't seem to be possible with most real browsers unless you rely on a scroll-and-stitch method that won't work with sticky parts of the page.

The reason is that Selenium require screenshots of viewports and not entire pages, therefore most drivers do not implement it. Exception is future Firefox with geckodriver as they have stated their interest in implementing it on their side.

You could use phantomjs with Selenium and a large window size as it seems it can resize beyond the viewport size. Example of Phantomjs desiredCapabilities:

"desiredCapabilities": { "browserName": "phantomjs", "javascriptEnabled": true, "acceptSslCerts": true, "phantomjs.binary.path": "../../../../node_modules/phantomjs-prebuilt/bin/phantomjs", "phantomjs.cli.args": ["--ignore-ssl-errors=true", "--web-security=false", "--ssl-protocol=any"] }