PhantomJS has the option of taking a screenshot of the whole page (not just the current viewport). Is there any way to do so using Selenium? I am running the Cucumber/Capybara tests headlessly, using the headless gem. I would use PhantomJS, but I've had some other problems with it.
Selenium Webdriver allows you to take a screenshot using the getScreenShotAs method of the TakeScreenshot Interface. You can take a screenshot of a viewable area, full-page, or particular element. For full-page Screenshot, we can use the third party library AShot that provides screenshot taking ability.
In order to capture a screenshot in Selenium, one has to utilize the method TakesScreenshot. This notifies WebDrive that it should take a screenshot in Selenium and store it. In the above snippet, OutputType defines the output type for the required screenshot.
In case anyone washed up this shore looking for how to do this with Poltergeist you just need to pass the full
argument:
page.save_screenshot('screen.png', full: true) # If providing a custom file name. page.save_screenshot(full: true) # Capybara sets a name based on timestamp. page.save_and_open_screenshot('screen.png', full: true) # Same as save_screenshot. page.save_and_open_screenshot(full: true) # Same as save_screenshot.
Docs.
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With