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.

3
  • 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. Commented Sep 15, 2013 at 15:45
  • The call of $this->currentWindow()->size() does affect the screenshot, but the size of the browser window itself.
    – SomeStupid
    Commented Sep 15, 2013 at 23:13
  • Ah, I didn't think of resizing. Glad you found an answer. Commented Sep 15, 2013 at 23:50

2 Answers 2

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,
));
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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.