2

As explained elsewhere (Take a screenshot with Selenium WebDriver), you can take screenshots easily with PHPUnit using the Selenium Webdriver class PHPUnit_Extensions_Selenium2TestCase .

However, I cannot find a way to set the screen size of the generated screenshots. By default, their width seems to be limited to 1000 pixels.

BTW: the above mentioned Stackoverflow thread is closed. So I cannot post my question there.

Community
  • 1
  • 1
SomeStupid
  • 101
  • 1
  • 10
  • I do not think this is possible. I believe that the width and height are those of the website that you are browsing. If a screenshot is not getting all of the webpage, then that is a different issue. If you only want part of a webpage, then you have to crop it yourself. – Nathan Merrill Sep 15 '13 at 15:45
  • The call of `$this->currentWindow()->size()` does affect the screenshot, but the size of the browser window itself. – SomeStupid Sep 15 '13 at 23:13
  • Ah, I didn't think of resizing. Glad you found an answer. – Nathan Merrill Sep 15 '13 at 23:50

2 Answers2

6

Have you tried to resize your browser window? I found interesting post about it here. Some code snippet from there:

    $this->currentWindow()->size(array(
  'width' => 800,
  'height' => 600,
));
Michal
  • 3,218
  • 2
  • 25
  • 44
3

Thank you very much! This solves my problem. I post my code to provide a more complete example:

You can get any window with $this->currentWindow()and then call the "closure method" size() on it. I put that into my setupPage() method.

class DrupalWebtestBase extends \PHPUnit_Extensions_Selenium2TestCase
{
    /* ... */

    public function setUpPage()
    {       
        parent::setUpPage();

        if( $this->width && $this->height )
        {    
            // main window is named ''  
            $this->window('');

            // get window object
            $window = $this->currentWindow();

            // set window size
            $window->size( array(
                            'width'     => $this->width,
                            'height'    => $this->height) );
        }
    }
}

The screenshots taken later on reflect the set window dimensions above.

SomeStupid
  • 101
  • 1
  • 10