SomeStupid
SomeStupid

Reputation: 101

Screenshots with Selenium Webdriver: How can I set the window size?

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.

Upvotes: 2

Views: 4534

Answers (2)

SomeStupid
SomeStupid

Reputation: 101

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.

Upvotes: 3

Michal
Michal

Reputation: 3276

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

Upvotes: 6

Related Questions