Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to take a screenshot of the whole page with Selenium/Capybara?

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.

like image 333
TrashyMcTrash Avatar asked May 22 '13 14:05

TrashyMcTrash


People also ask

Can we take full page screenshot in Selenium?

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.

Which is the method of Selenium WebDriver to capture the screenshots?

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.


1 Answers

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!

like image 103
Gabriel Osorio Avatar answered Sep 19 '22 02:09

Gabriel Osorio