Dusk: Screenshot full page

Created on 19 Jul 2017  路  4Comments  路  Source: laravel/dusk

How to screenshot full page? This issue did't help me
https://github.com/laravel/dusk/issues/279

Most helpful comment

I added this method to DuskTestCase
```
protected function captureFailuresFor($browsers)
{
$browsers->each(function (Browser $browser, $key) {
$body = $browser->driver->findElement(WebDriverBy::tagName('body'));
if (!empty($body)) {
$currentSize = $body->getSize();
$size = new WebDriverDimension($currentSize->getWidth(), $currentSize->getHeight());
$browser->driver->manage()->window()->setSize($size);
}
$browser->screenshot('failure-'.$this->getName().'-'.$key);
});
}

All 4 comments

I am having same issue.

$response = $browser->visit( url for page with scroll on Y-axis); $response->resize(1100, 2500)->driver->takeScreenshot($path);

it will only take screen shot of browser visible area on screen, even if you make width and height dynamic using following

$element = $response->element('body'); $element_width = $element->getSize()->getWidth(); $element_height = $element->getSize()->getHeight();

I added this method to DuskTestCase
```
protected function captureFailuresFor($browsers)
{
$browsers->each(function (Browser $browser, $key) {
$body = $browser->driver->findElement(WebDriverBy::tagName('body'));
if (!empty($body)) {
$currentSize = $body->getSize();
$size = new WebDriverDimension($currentSize->getWidth(), $currentSize->getHeight());
$browser->driver->manage()->window()->setSize($size);
}
$browser->screenshot('failure-'.$this->getName().'-'.$key);
});
}

I'm having the same issue, when a test fails I only get a cropped screenshot. Overriding the captureFailuresFor() method solves the problem. But why this isn't working properly by default? Could it be something in my environment?

I'm using Laravel 5.5 on Ubuntu.

To the answer of @xakzona remember to add this to the top of the file:

use Laravel\Dusk\Browser;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverDimension;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

muswanto picture muswanto  路  3Comments

dborovsky picture dborovsky  路  7Comments

fwang-laralabs picture fwang-laralabs  路  6Comments

antonioribeiro picture antonioribeiro  路  5Comments

bruno-barros picture bruno-barros  路  6Comments